linux 在線完美安裝mysql2.7.22
1、下載tar包,可直接服務器在線下載
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
2、將mysql安裝到/usr/local/mysql下
# 解壓
tar -xvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
# 移動
mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/
# 重命名
mv /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
3、新建data目錄
mkdir /usr/local/mysql/data
4、新建mysql用戶、mysql用戶組
# mysql用戶組
groupadd mysql
# mysql用戶
useradd mysql -g mysql
5、將/usr/local/mysql的所有者及所屬組改為mysql
chown -R mysql.mysql /usr/local/mysql
6、配置
/usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
# 編輯/etc/my.cnf
[mysqld] datadir=/usr/local/mysql/data basedir=/usr/local/mysql socket=/tmp/mysql.sock user=mysql port=3306 character-set-server=utf8
# 取消密碼驗證
skip-grant-tables # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # skip-grant-tables [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
7、開啟服務
# 將mysql加入服務
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
# 開機自啟
chkconfig mysql on
# 開啟
service mysql start
8、設置密碼
# 登錄(由於/etc/my.cnf中設置了取消密碼驗證,所以此處密碼任意)
/usr/local/mysql/bin/mysql -u root -p
# 操作mysql數據庫
>>use mysql;
# 修改密碼
>>update user set authentication_string=password(‘你的密碼‘) where user=‘root‘;
>>flush privileges;
>>exit;
9、將/etc/my.cnf中的skip-grant-tables刪除
10、登錄再次設置密碼(不知道為啥如果不再次設置密碼就操作不了數據庫了)
/usr/local/mysql/bin/mysql -u root -p
>>ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘修改後的密碼‘;
>>exit;
11、允許遠程連接
/usr/local/mysql/bin/mysql -u root -p
>>use mysql;
>>update user set host=‘%‘ where user = ‘root‘;
>>flush privileges;
>>exit;
12、添加快捷方式
ln -s /usr/local/mysql/bin/mysql /usr/bin
linux 在線完美安裝mysql2.7.22