1.下載
mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz
2.解壓
tar -xvf mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.15-linux-glibc2.12-x86_64 mysql
mv mysql /usr/local
cd /usr/local/mysql
mkdir data
3.編輯 my.cnf
vi /etc/my.cnf
文件內容為:

[client]port=3306socket=/tmp/mysql/mysql.sock[mysqld]port=3306user=mysqlsocket=/tmp/mysql/mysql.sockbasedir=/usr/local/mysqldatadir=/usr/local/mysql/datalog-error=error.logtransaction_isolation = READ-COMMITTEDcharacter-set-server = utf8mb4collation-server = utf8mb4_general_cilower_case_table_names = 1#skip-grant-tables

4.創(chuàng )建用戶(hù)
groupadd mysql
useradd -g mysql mysql
5.更改目錄權限
chown -R mysql:mysql /tmp/mysql
chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /tmp/mysql /usr/local/mysql
6. 初始化
cd /usr/local/mysql
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
7.初始化密碼
初始化時(shí)并沒(méi)有出現 初始密碼,因此需要修改密碼。
注釋 skip-grant-tables,可以使用無(wú)密碼登錄
啟動(dòng) mysql
./support-files/mysql.server start
1.清空密碼
use mysql;
update user set authentication_string='' where user='root';
2.無(wú)密碼登錄
mysql -u root -p
輸入密碼是直接回車(chē)。
ALTER user 'root'@'localhost' IDENTIFIED BY 'root';
這樣就修改好密碼了。

自此 mysql 就安裝好了。

8 設置自動(dòng)啟動(dòng)
cd support-files/
cp mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
cd /etc/init.d
chkconfig --add mysql
chkconfig --level 345 mysql on
mysql restart
9. 遠程連接
1.在 my.cnf 的mysqld 下增加
default_authentication_plugin=mysql_native_password
2.進(jìn)入mysql命令行
use mysql
update user set host ='%' where user='root';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
FLUSH PRIVILEGES;
使用客戶(hù)端工具進(jìn)行連接。
聯(lián)系客服