centos7.6下安裝mysql8.0.23
系統環境:centos7.6
mysql版本:8.0.23
下載地址:https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz
解壓檔案:
tar -xvf mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz
資料夾改名:
mv mysql-8.0.23-linux-glibc2.12-x86_64 mysql
建立配置資料夾
mkdir /usr/local/mysql/conf
建立資料目錄:
mkdir /data
mkdir /data/mysql
mkdir /data/mysql/binlog
建立使用者:
useradd -s /sbin/nologin mysql
授權:
chown -R mysql /usr/local/mysql
chown -R mysql /data
設定環境變數:
vim /etc/profile.d/mysql.sh
輸入內容:
export PATH=/usr/local/mysql/bin:$PATH
載入配置:
source /etc/profile.d/mysql.sh
開機啟動
vim /etc/systemd/system/mysqld.service
輸入內容:
[Unit] Description=MySQL Server Documentation=man:mysqld(8) Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html After=network.target After=syslog.target [Install] WantedBy=multi-user.target [Service] User=mysql Group=mysql ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/conf/my.cnf LimitNOFILE = 5000
重新載入配置檔案
systemctl daemon-reload
systemctl enable mysqld
建立Mysql 配置檔案
vim /usr/local/mysql/conf/my.cnf
內容:
[client] port=3306 socket=/usr/local/mysql/mysql.sock default-character-set = utf8mb4 [mysqld] basedir=/usr/local/mysql datadir=/data/mysql/data port=3306 socket=/usr/local/mysql/mysql.sock pid-file=/usr/local/mysql/mysql.pid log-error=/data/mysql/mysql_error.log log-bin=/data/mysql/binlog/binlog max_connections = 300 character-set-server = utf8mb4 default-storage-engine = INNODB lower_case_table_names = 1 default_authentication_plugin = mysql_native_password skip-host-cache skip-name-resolve #獨立表空間 innodb_file_per_table = 1 #記憶體池 innodb_buffer_pool_size = 2G innodb_flush_log_at_trx_commit = 1 [mysql] default-character-set = utf8mb4 socket = /var/lib/mysql/mysql.sock [mysqld_safe]
說明:
default_authentication_plugin:設定密碼規則,caching_sha2_password是預設的身份驗證外掛,為方便使用 mysql_native_password
lower_case_table_names:忽略大寫小,建議設定,方便業務
其餘設定根據需求更改
初始化資料庫
/usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/conf/my.cnf --initialize --user=mysql
查詢密碼:
grep "password" /data/mysql/mysql_error.log
#啟動資料庫
systemctl start mysqld
登入系統,密碼為查詢出的密碼
mysql -uroot -p -S /usr/local/mysql/mysql.sock
修改密碼:
alter user root@'localhost' identified WITH mysql_native_password by '123456';
設定遠端連線
use mysql
update user set host ='%' where user ='root';
flush privileges;