1. 程式人生 > 實用技巧 >CentOS 7.2 下 mysql 8.0.11二進位制安裝(親測)

CentOS 7.2 下 mysql 8.0.11二進位制安裝(親測)

本文主要介紹mysql 8.0.11二進位制安裝,具體步驟如下

1. 解壓檔案

tar -zxvf mysql-8.0.11-el7-x86_64.tar.gz


2. 移動解壓後的資料庫檔案

mv mysql-8.0.11-el7-x86_64 /usr/local/mysql


3. 建立mysql組

groupadd mysql


4. 建立mysql使用者並新增到mysql組

useradd -g mysql mysql


5. 建立data目錄

mkdir /data


6. 修改目錄許可權

chown -R mysql.mysql /data

chown -R mysql.mysql /usr/local/mysql


7. 建立my.cnf檔案(etc目錄下已有my.cnf,可先刪除)

vi /etc/my.cnf

[mysqld]

port = 3306

socket = /tmp/mysql.sock

basedir = /usr/local/mysql

datadir = /data

log-error = mysql02_err.log

server-id = 330602


8.初始化資料庫

(mysql 8.0.11是沒有/bin/mysql_install_db指令碼的,有的人寫教程仍在用來誤導新人,安裝不成功的請注意。官檔可查)

#有密碼初始化

/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --user=mysql --initialize

無密碼初始化

/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --user=mysql --initialize-insecure


9. 檢視密碼

cat /data/mysql02_err.log

2018-07-25T14:10:46.576739Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.11) initializing of server in progress as process 9796

2018-07-25T14:10:49.072963Z 5 [Note] [MY-010454] [Server] A temporary password is generated for

[email protected]: iN:.snX3P_in

2018-07-25T14:10:50.825865Z 0 [System] [MY-013170] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.11) initializing of server has completed


10. 啟動資料庫

/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &


[1] 9925

2018-07-25T14:20:27.230347Z mysqld_safe Logging to '/data/mysql02_err.log'.

2018-07-25T14:20:27.267638Z mysqld_safe Starting mysqld daemon with databases from /data


11. 登入資料庫

/usr/local/mysql/bin/mysql -uroot -p


12. 第一次登入修改root初始化密碼

alter user 'root'@'localhost' identified with mysql_native_password by '123456'


13. 建立[email protected]%

create user 'root'@'%' identified by '123456';

grant all privileges on *.* to 'root'@'%' with grant option;

flush privileges;


14. 配置環境變數

vi /etc/profile 在最後新增:

PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH

source /etc/profile


15. 關閉資料庫

mysqladmin -uroot -p shutdown


16. 啟動資料庫

mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &


17. 檢視資料庫程序

[[email protected] data]# ps -ef|grep mysql

root 10253 9892 0 10:48 pts/2 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql

mysql 10405 10253 16 10:48 pts/2 00:00:01 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mysql02_err.log --pid-file=mysql02.pid --socket=/tmp/mysql.sock --port=3306

root 10447 9892 0 10:49 pts/2 00:00:00 grep --color=auto mysql


18. 將mysql服務加到系統服務中

cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql.server

chmod +x /etc/rc.d/init.d/mysql.server

chkconfig --add mysql.server

chkconfig --list mysql.server


19. 關閉資料庫

service mysql.server stop

[[email protected] etc]# service mysql.server stop

Shutting down MySQL..2018-07-25T15:33:26.490180Z mysqld_safe mysqld from pid file /data/mysql02.pid ended

SUCCESS!

[1]+ Done mysqld_safe --defaults-file=/etc/my.cnf --user=mysql (wd: /data)

(wd now: /etc)


20. 啟動資料庫

sudo -u mysql service mysql.server start

[[email protected] etc]# sudo -u mysql service mysql.server start

Starting MySQL.. SUCCESS!


21. 檢視服務

ps -ef|grep mysql

[[email protected] etc]# ps -ef|grep mysql

mysql 10833 1 0 11:35 pts/2 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data --pid-file=/data/mysql02.pid

mysql 11003 10833 10 11:35 pts/2 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=mysql02_err.log --pid-file=/data/mysql02.pid --socket=/tmp/mysql.sock --port=3306

root 11047 9892 0 11:36 pts/2 00:00:00 grep --color=auto mysql


22. 重啟資料庫

sudo -u mysql service mysql.server restart

[[email protected] etc]# sudo -u mysql service mysql.server restart

Shutting down MySQL.. SUCCESS!

Starting MySQL. SUCCESS!

blob.png

(本文出處:易語隨風去 https://blog.51cto.com/aimax)

轉載於:https://blog.51cto.com/aimax/2150021