環(huán)境
系統(tǒng):CentOS 7.8
軟件:mysql-5.7.41-linux-glibc2.12-x86_64.tar.gz
安裝
-
下載二進(jìn)制包
- 瀏覽器下載:https://downloads.mysql.com/archives/community/
- wget下載:
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.41-linux-glibc2.12-x86_64.tar.gz
-
安裝依賴
yum install -y libaio
-
創(chuàng)建MySQL用戶
useradd mysql
-
解壓二進(jìn)制包
tar -xzvf mysql-5.7.41-linux-glibc2.12-x86_64.tar.gz mv mysql-5.7.41-linux-glibc2.12-x86_64 /usr/local/mysql
-
配置環(huán)境變量
cat << EOF >> /etc/profile # mysql export PATH=/usr/local/mysql/bin:\$PATH EOF
source /etc/profile
配置
-
配置my.cnf
mkdir /usr/local/mysql/etc touch /usr/local/mysql/etc/my.cnf ln -sf /usr/local/mysql/etc/my.cnf /etc/
cat << EOF > /etc/my.cnf [mysqld_safe] log-error=/usr/local/mysql/log/mysql.err [mysqld] datadir=/usr/local/mysql/data tmpdir=/usr/local/mysql/tmp socket=/usr/local/mysql/run/mysql.sock user=mysql character_set_server=utf8mb4 default-storage-engine=INNODB innodb_buffer_pool_size=1G slow_query_log=1 slow_query_log_file=/usr/local/mysql/log/mysql.slow long_query_time=2 server_id=1 log-bin=/usr/local/mysql/log-bin/log-bin binlog_format=MIXED expire_logs_days=7 max_connections=1000 [client] socket=/usr/local/mysql/run/mysql.sock EOF
-
配置數(shù)據(jù)和日志目錄
mkdir -p /data/mysql/{data,log,log-bin,run,tmp} ln -s /data/mysql/{data,log,log-bin,run,tmp} /usr/local/mysql/ touch /usr/local/mysql/log/mysql.err chown -R mysql:mysql /data/mysql chown -R mysql:mysql /usr/local/mysql
-
初始化
mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 輸出如下: ...... A temporary password is generated for root@localhost: xxx
記住生成的臨時密碼xxx
啟動
-
啟動
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on /etc/init.d/mysqld restart
-
運(yùn)行安全配置向?qū)?/p>
mysql_secure_installation -S /usr/local/mysql/run/mysql.sock 輸入如下: Enter password for user root: 輸入剛才的臨時密碼 New password: Re-enter new password: Press y|Y for Yes, any other key for No: n Change the password for root ? ((Press y|Y for Yes, any other key for No) : n Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
配置賬戶權(quán)限
- root賬戶遠(yuǎn)程訪問
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your_password' WITH GRANT OPTION; FLUSH PRIVILEGES;