centos安裝mysql5.7 (docker環境)
阿新 • • 發佈:2018-12-28
centos安裝mysql5.7 (docker環境)
- yum安裝依賴
yum -y install libaio numactl
yum -y install openssl openssl-devel
如果要使用mysql的ssl加密通訊則安裝,否則跳過此步驟
- 前期準備工作
groupadd mysql
建立mysql組useradd -g mysql mysql -s /sbin/nologin
建立MySQL使用者並且不讓shell登入mkdir -p /usr/local/mysql/data && cd /usr/local/mysql
wget -c https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
下載mysql通用二進位制包tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz && mv mysql-5.7.24-linux-glibc2.12-x86_64/* /usr/local/mysql && cd /usr/local/mysql
解壓並且進入目錄chown -R mysql:mysql /usr/local/mysql
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
初始化資料庫/usr/local/mysql/bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
mysql的ssl加密通訊,如果不使用,則跳過此步驟
- 配置啟動MySQL
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
vim /etc/init.d/mysqld
- 新增路徑 在46行
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data vim /etc/my.cnf
將一下程式碼複製過去[mysqld] character_set_server=utf8 init_connect='SET NAMES utf8' basedir=/usr/local/mysql datadir=/usr/local/mysql/data socket=/tmp/mysql.sock #不區分大小寫(sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 這個簡單來說就是sql語句是否嚴格) lower_case_table_names = 1 log-error=/var/log/mysqld.log pid-file=/usr/local/mysql/data/mysqld.pid
chkconfig --add mysqld
開機啟動MySQLln -s /usr/local/mysql/bin/mysql /usr/bin
新增軟連線/etc/init.d/mysqld start
啟動MySQL服務mysql -uroot -p
登入MySQLalter user 'root'@'localhost' identified by '123456'
修改密碼grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option
授權MySQL的root使用者可以在任意地址登入且能將自己許可權分配給別人flush privileges
重新整理許可權