1.01:環境
CentOS Linux 7 (Core)
mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz
1.02:數據庫下載地址:
https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz
1.03:添加用戶組和用戶:
groupadd mysql
useradd -r -g mysql mysql
1.04:創建數據和日誌文件夾:
mkdir -p /data/mysql /logs/mysql /var/lib/mysql /tmp_mysql
1.05:解壓mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz 到/usr/local/
xz -d mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz
tar xvf mysql-8.0.16-linux-glibc2.12-x86_64.tar -C /usr/local/mysql
1.06:修改mysql相關文件夾權限:
chown -R mysql:mysql /usr/local/mysql/
chown -R mysql:mysql /data/mysql/
chown -R mysql:mysql /logs/mysql/
chown -R mysql:mysql /var/lib/mysql/
chown -R mysql:mysql /tmp_mysql
chmod -R 777 /usr/local/mysql/
chmod -R 777 /data/mysql/
chmod -R 777 /logs/mysql/
chmod -R 777 /var/lib/mysql/
chmod -R 777 /tmp_mysql
1.07:簡單配置my.cnf:
vim /etc/my.cnf
配置如下:
[mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/logs/mysql/error.log
port=3306
user=mysql
server-id=3306
symbolic-links=0
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
default-time-zone='+8:00'
max_connections=1000
max_connect_errors=1000
tmp_table_size=256M
max_heap_table_size=256M
log-bin=/data/mysql/mysql-bin
expire_logs_days=7
tmpdir=/tmp_mysql
# 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]
pid_file=/data/mysqld/mysqld.pid
log_error=/logs/mysql/error.log
#
# include all files from the config directory
#
[client]
socket=/data/mysql/mysql.sock
default-character-set=utf8mb4
!includedir /etc/my.cnf.d
1.08:創建連接:
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
ln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump
1.09:初始化數據庫:
cd /usr/local/mysql/
./bin/mysqld --defaults-file=/etc/my.cnf --initialize
1.10:啓動數據庫:
./bin/mysqld --defaults-file=/etc/my.cnf &
1.11:查看臨時登錄密碼:
cat /logs/mysql/error.log | grep password
1.12:修改root密碼:
mysql -uroot -p
-- 密碼換成123456,可以換成你需要的密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
1.13:設定root遠程訪問:
UPDATE mysql.user SET HOST='%' WHERE USER='root';
FLUSH PRIVILEGES;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
FLUSH PRIVILEGES;
1.14:開放3306端口:
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --reload
1.15:增加mysql服務並設置開機啓動:
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chkconfig --add mysql
chkconfig --level 2345 mysql on