買了個阿里雲,本身折騰一下。mysql
時間:2019年7月17日13:40:18linux
一、下載sql
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
二、解壓vim
tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
三、移動文件到 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/
四、增長用戶組socket
groupadd mysql useradd -r -g mysql mysql
五、修改當前目錄擁有者爲mysql用戶:執行命令 ui
chown -R mysql:mysql ./
六、安裝this
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 這個是隨機密碼阿里雲
初始化完畢後在命令行最後會提供生成好的隨機密碼,先拷貝下來spa
七、修改權限
而後修改下權限,把除了data外的全部mysql文件的權限都設置爲root
chown -R root:root ./
chown -R mysql:mysql data
八、啓動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 ]
沒錯,綠色是我本身改的!!
搞定了
九、改密碼
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) 完事!
十、備註一下,3306端口默認開放,若是用Navicat去連的話,阿里雲服務器連不上,上阿里雲控制檯