linux mysql-5.7.26 安裝全記錄


買了個阿里雲,自己折騰一下。

時間:2019年7月17日13:40:18

1、下載

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

2、解壓

tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz 

3、移動文件到 usr/local/mysql目錄下

mv mysql-5.7.26-linux-glibc2.12-x86_64 /usr/local/mysql
發現寫錯了,移到上層目錄
cd /usr/local/mysql/
cd mysql-5.7.26-linux-glibc2.12-x86_64/
cd ..
mv mysql-5.7.26-linux-glibc2.12-x86_64/* ./
rm -rf mysql-5.7.26-linux-glibc2.12-x86_64/

4、增加用戶組

groupadd mysql

useradd -r -g mysql mysql

5、修改當前目錄擁有者為mysql用戶:執行命令 

chown -R mysql:mysql ./

6、安裝

cd /usr/local/mysql/bin/
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
報錯了
rpm -qa|grep libaio
yum install  libaio-devel.x86_64
安裝一個這玩意
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 
再執行,有warn 沒error了

2019-07-17T05:51:34.038056Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-07-17T05:51:35.100511Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-07-17T05:51:35.223640Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-07-17T05:51:35.287407Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: efa727f9-a856-11e9-96d2-00163e063119.
2019-07-17T05:51:35.289478Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-07-17T05:51:35.289924Z 1 [Note] A temporary password is generated for root@localhost: gpPkXgqLT1=S   這個是隨機密碼

 

初始化完畢后在命令行最后會提供生成好的隨機密碼,先拷貝下來

7、修改權限

然后修改下權限,把除了data外的所有mysql文件的權限都設置為root
chown -R root:root ./
chown -R mysql:mysql data

8、啟動mysql服務和添加開機啟動mysql服務

添加開機啟動:執行命令cp support-files/mysql.server /etc/init.d/mysql,把啟動腳本放到開機初始化目錄
啟動mysql服務:執行命令 service mysql start

Starting MySQL.2019-07-17T05:59:19.660315Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
The server quit without updating PID file (/var/lib/mysql/i[FAILED]gohhgjiy8uy2gZ.pid).
pwd
/usr/local/mysql
報錯,權限問題還是文件夾沒有。。

建一個

mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql /var/log/mariadb/
service mysql start
Starting MySQL.2019-07-17T06:02:23.769297Z mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
The server quit without updating PID file (/var/lib/mysql/i[FAILED]gohhgjiy8uy2gZ.pid).

又少了啥

mkdir   /var/lib/mysql

chmod 777  /var/lib/mysql

service mysql start

Starting MySQL....The server quit without updating PID file[FAILED]ib/mysql/iZ2ze967kgohhgjiy8uy2gZ.pid).

日了。。

去/etc/下看看 my.cnf

vim /etc/my.cnf

發現datadir 不是咱指定的那個

改一下

datadir = /usr/local/mysql/data

保存,再啟動。

service mysql start
Starting MySQL. [ OK ]

沒錯,綠色是我自己改的!!

搞定了

9、改密碼

mysql -u root -p
登錄,密碼就是上面標紅的位置
會提示
ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
意思就是密碼要過期了。

./mysql -u root -p
再登錄一遍
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.26

mysql> set password = password('1111');
Query OK, 0 rows affected, 1 warning (0.00 sec)

完事!

10、備注一下,3306端口默認開放,如果用Navicat去連的話,阿里雲服務器連不上,上阿里雲控制台

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM