安裝MySQL版本為:8.0.16 1、首次安裝,下載命令: wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz 2、解壓 tar xvJf mysql-8.0.2 ...
安裝MySQL版本為:8.0.16
1、首次安裝,下載命令:
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
2、解壓
tar xvJf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
3.重命名
mv mysql-8.0.20-linux-glibc2.12-x86_64 mysql-8.0
4.創建用戶組、用戶及其密碼
groupadd mysql
useradd -g mysql mysql
6、授權
chown -R mysql.mysql /usr/local/mysql/mysql-8.0
chmod 750 /usr/local/mysql/mysql-8.0/data -R
7、在 /etc/profile 中添加環境變數 並執行 source /etc/profile
export PATH=$PATH:/usr/local/mysql/mysql-8.0/bin:/usr/local/mysql/mysql-8.0/lib
8、配置 /etc/my.cnf
[mysql] default-character-set=utf8mb4 [client] #port=3306 socket=/var/lib/mysql/mysql.sock [mysqld] #port=3306 #server-id=3306 user=mysql general_log = 1 general_log_file= /var/log/mysql/mysql.log socket=/var/lib/mysql/mysql.sock basedir=/usr/local/mysql datadir=/usr/local/mysql/data log-bin=/usr/local/mysql/data/mysql-bin innodb_data_home_dir=/usr/local/mysql/data innodb_log_group_home_dir=/usr/local/mysql/data/ character-set-server=utf8mb4 lower_case_table_names=1 autocommit=1 default_authentication_plugin=mysql_native_password symbolic-links=0 # Disabling symbolic-links is recommended to prevent assorted security risks # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/usr/local/mysql/data/mysql.log pid-file=/usr/local/mysql/data/mysql.pid
9、在/usr/local/mysql/mysql-8.0/bin目錄下執行 執行初始化指令
./mysqld --user=mysql --basedir=/usr/local/mysql/mysql-8.0 --datadir=/usr/local/mysql//mysql-8.0/data/ --initialize
操作成功後會給出臨時密碼:%8s/H*uB!(ed
10、進入/usr/local/mysql/mysql-8.0目錄 複製mysql執行文件 並賦予許可權
cp -a ./support-files/mysql.server /etc/init.d/mysql
cp -a ./support-files/mysql.server /etc/init.d/mysqld
授權
chown 777 /etc/my.cnf
chmod +x /etc/init.d/mysql
chmod +x /etc/init.d/mysqld
11、創建文件夾 mkdir /var/lib/mysql 並授權
chown -R mysql:mysql /var/lib/mysql/
12、啟動MySQL
service mysql start
# SUCCESS 則表示成功
13、用戶登錄
mysql -uroot -p
此時輸入 初始化操作給出的密碼就可以登錄了
password:%8s/H*uB!(ed (這裡輸入之前保存的臨時密碼即可)
14、修改密碼
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密碼';
flush privileges;#刷新許可權
15、設置遠程連接
use mysql; # 選擇資料庫
mysql> create user 'root'@'%' identified by 'password';
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
mysql> flush privileges;
16、到這裡,整個安裝過程結束。
***遇到的問題
1、許可權問題
解決方法:chown mysql:mysql /var/log/mysql/mysql.log
2、data文件夾已存在 刪掉data文件夾即可 初始化時自動創建
3、MySQL登錄
這裡需要輸入,之前保存的臨時密碼,其他任何值都會報錯!