天天看點

Linux伺服器部署mysql5.7.x 二進制包

mysql5.7的安裝相對于5.6還是有點差別,本章主要介紹二進制的安裝方法。

mysql 5.7下載下傳位址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

安裝

我下載下傳的是版本是mysql5.7.22社群版 

解壓拷貝

mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql      

先建立mysql使用者

groupadd mysql
useradd  mysql -s /sbin/nolongin      

建立mysql的資料目錄,該目錄在初始化資料庫的時候會用到

mkdir /mysql /mysql/data /mysql/log      

修改目錄權限

chown -R mysql:mysql /usr/local/mysql /mysql      

建立my.cnf檔案

vim /etc/my.cnf

省略

說明:這裡隻是進行了一些簡單的配置 

初始化資料庫

在5.7.6之前初始化的方法是:

bin/mysql_install_db --user=mysql

我下載下傳的是最新的5.7.12也是4.12号剛釋出的版本,5.7.6之後的版本初始化資料庫不再使用mysql_install_db

bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/application/data  --explicit_defaults_for_timestamp (預設會讀/etc/my.cnf)      

 如果配置了my.cnf的log_error,那麼初始密碼在log_error檔案中,否則會列印出來。

bin/mysql_ssl_rsa_setup --datadir=/mysql/data      

初始化遇到的錯誤

[ERROR] Can't find error-message file '/usr/local/mysql/--datadir=/usr/local/mysql/data/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' con

error-message file路徑要和basedir 位址保持一緻即可解決以上錯誤

[root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/application/data  --explicit_defaults_for_timestamp  

bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

解決方案:

[root@localhost mysql]# yum install numactl -y

bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

解決方案:

[root@localhost mysql]# yum install -y libaio

chown -R mysql:mysql /usr/local/mysql /mysql      

配置啟動檔案

cp support-files/mysql.server /etc/init.d/mysql      
chkconfig --add mysql
chkconfig mysql on      
service mysql start      
mysql_home=/usr/local/mysql
PATH=$PATH:$mysql_home/bin      
source /etc/profile      
 mysqladmin -uroot -p舊密碼  password 新密碼 -S /usr/local/mysql/mysql.sock      
 update mysql.user set authentication_string=password('yourpassword') where user='root' and Host = 'localhost';      

繼續閱讀