安裝之前 確認是否已安裝舊版mysql。如有,則卸載(註意需要的數據備份)。 /etc/init.d/mysqld stop yum remove mysql mysql rm rf /var/lib/mysql rm /etc/my.cnf 下載 下載 wget https://dev.mysql ...
安裝之前
確認是否已安裝舊版mysql。如有,則卸載(註意需要的數據備份)。
/etc/init.d/mysqld stop
yum remove mysql mysql-*
rm -rf /var/lib/mysql
rm /etc/my.cnf
下載
下載
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
解壓
tar xzf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
移動到目錄
mv mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/mysql
配置
創建數據目錄,如
mkdir /usr/local/mysql_data
修改/etc/my.cnf,沒有則創建,輸入以下內容:
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
skip-name-resolve
sql_mode=""
max_connections=10000
datadir=/usr/local/mysql_data
socket=/tmp/mysql.sock
user=mysql
Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character-set-server=utf8mb4
collation_server=utf8mb4_unicode_ci
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
配置mysql目錄用戶及許可權
groups mysql (檢查是否存在mysql組,沒有則創建)
- groupadd mysql (如不存在)
su mysql (檢查是否存在mysql用戶,沒有則創建) - useradd -r -g mysql mysql (如不存在)
cd /usr/local/mysql/
chown -R mysql:mysql ./
初始化
./bin/mysqld --initialize --user=mysql
註意這裡會生成一個臨時密碼,記住它,第一次登陸時需要
可能遇到的錯誤:
libaio.so.1: cannot open shared object file
解決:yum install libaio
再次修改mysql目錄用戶及許可權
cd /usr/local/mysql/
chown -R root:root ./
cd /usr/local/mysql_data
chown -R mysql:mysql ./
啟動mysqld
cd /usr/local/mysql/
./bin/mysqld &
初次訪問
建立軟鏈接,將mysql命令加入可執行檢索路徑中
ln -s /usr/local/mysql/bin/mysql /bin/mysql
訪問mysql
mysql -uroot -p -h localhost
按提示輸入初次密碼
更改密碼
UPDATE mysql.user SET Password=PASSWORD('your_new_password')
WHERE User='root';
報錯後執行:
SET PASSWORD = PASSWORD('your_new_password');
授權遠程登錄
grant all privileges on . to root@'%' identified by 'your_new_password';
flush privileges;
退出mysql。
配置mysql服務方便自啟動
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
服務命令
service mysqld status
service mysqld start
service mysqld stop
service mysqld restart