本文主要介紹mysql 8.0.11二進制安裝,具體步驟以下mysql
1. 解壓文件sql
tar -zxvf mysql-8.0.11-el7-x86_64.tar.gz數據庫
2. 移動解壓後的數據庫文件socket
mv mysql-8.0.11-el7-x86_64 /usr/local/mysqlide
3. 建立mysql組spa
groupadd mysqlrest
4. 建立mysql用戶並添加到mysql組server
useradd -g mysql mysqlblog
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 root@localhost: 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. 建立root@%
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. 查看數據庫進程
[root@mysql02 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
[root@mysql02 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
[root@mysql02 etc]# sudo -u mysql service mysql.server start
Starting MySQL.. SUCCESS!
21. 查看服務
ps -ef|grep mysql
[root@mysql02 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
[root@mysql02 etc]# sudo -u mysql service mysql.server restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
(本文出處:易語隨風去 https://blog.51cto.com/aimax)