前言css
最近整理下在Linux CentOS7系統下安裝mysql8.0.13版本的一些步驟和遇到的問題,分享給你們!前端
一mysql
安裝和報錯處理linux
1.進入到https://www.mysql.com/downloads/msyql下載頁,選擇社區版nginx
2.查看linux版本,選擇對應的版本下載web
3.將下載的文件mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz拷貝到linux服務器上的某目錄下,而後解壓,再複製到usr/local目錄,並更名爲mysqlsql
[root@VM_0_14_centos mysql]# tar -xvf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz[root@VM_0_14_centos mysql]# cp -rv mysql-8.0.13-linux-glibc2.12-x86_64 /usr/local[root@VM_0_14_centos mysql]# cd /usr/local [root@VM_0_14_centos local]# mv mysql-8.0.13-linux-glibc2.12-x86_64 mysql
4.添加mysql用戶數據庫
useradd -s /sbin/nologin -M mysql
5.msyql初始化vim
/usr/local/mysql/bin/mysqld --initialize --user=mysql
此時會生成臨時密碼centos
[ ]2019-01-20T10:56:07.718326Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 58262019-01-20T10:56:16.915217Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: twi=Tlsi<0O!2019-01-20T10:56:20.410563Z 0 [System] [MY-013170] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.13) initializing of server has completed
6.複製啓動、關閉腳本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
7.修改配置文件,wq保存退出
vim /etc/my.cnf[ ] basedir = /usr/local/mysql datadir = /var/lib/mysql socket = /var/lib/mysql/mysql.sock character-set-server=utf8 [ ] socket = /var/lib/mysql/mysql.sock default-character-set=utf8
8.啓動數據庫服務
service mysqld start
報錯
mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
一是由於沒有/var/lib/mysql這個目錄,二是沒有寫的權限,mysql.sock文件沒法生成。
[ ][ ]
再次運行service mysqld start報另外一個錯
Starting MySQL. ERROR! The server quit without updating PID file (/var/lib/mysql/VM_0_14_centos.pid).
打印出具體報錯信息
[ ]2019-01-20T11:11:45.906800Z 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.13) starting as process 77882019-01-20T11:11:45.910813Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.2019-01-20T11:11:45.925456Z 1 [ERROR] [MY-011011] [Server] Failed to find valid data directory.2019-01-20T11:11:45.925586Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.2019-01-20T11:11:45.925600Z 0 [ERROR] [MY-010119] [Server] Aborting2019-01-20T11:11:45.926342Z 0 [System] [MY-010910] [Server] /usr/local/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.13) MySQL Community Server - GPL.2019-01-20T11:12:00.049920Z 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.13) starting as process 79752019-01-20T11:12:00.052469Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.2019-01-20T11:12:00.060600Z 1 [ERROR] [MY-011011] [Server] Failed to find valid data directory.2019-01-20T11:12:00.060745Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.2019-01-20T11:12:00.060759Z 0 [ERROR] [MY-010119] [Server] Aborting2019-01-20T11:12:00.061610Z 0 [System] [MY-010910] [Server] /usr/local/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.13) MySQL Community Server - GPL.
看不出來具體是哪裏的問題,因而運行service --status-all,有報錯信息
ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists
有網友說刪了該文件就能夠,結果我刪了也沒用。
那就接着排查剛纔的err文件,關鍵的錯誤應該是這兩行
2019-01-20T11:11:45.925456Z 1 [ERROR] [MY-011011] [Server] Failed to find valid data directory.2019-01-20T11:11:45.925586Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
因而查找my.cnf,與data目錄有關的就是datadir=/var/lib/mysql這一條配置了,我嘗試性地刪了這一行,結果成功了,service mysqld start成功!
9.mysql -u root -p登陸mysql報錯
解決方法以下:
cd /usr/local/bin ln -fs /usr/local/mysql/bin/mysql mysql
10.show databases報錯
you must reset your password using ALTER USER statement before executing this statement.
解決方法:
alter user user() identified by '123456';
11.用ip沒法遠程登陸mysql,只能用localhost在linux服務器登陸
修改權限配置
grant all privileges on *.* to 'root'@'%' identified by '123456';
可是報錯
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by '123456' at line 1
解決方法:
use mysql;update user set host = '%' where user = 'root';flush privileges;
接着用navicat鏈接時報錯
Client does not support authentication protocol requested by server; consider upgrading MySQL client
解決方法:
ALTER USER 'root'@'*' IDENTIFIED WITH mysql_native_password BY '123456';
本文分享自微信公衆號 - 大前端技術沙龍(is_coder)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。