安裝 mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
阿新 • • 發佈:2019-02-17
1.下載和解壓mysql資料庫
sudo cp -r mysql-5.7.11-linux-glibc2.5-x86_64 /usr/local/
cd /usr/local
sudo mv mysql-5.7.11-linux-glibc2.5-x86_64/ mysql-5.7.11
2.建立軟連結
sudo ln -s mysql-5.7.11 mysql
3.建立mysql使用者和修改軟體的許可權
sudo -s
useradd -r -M -s /sbin/nologin mysql
chown -R mysql.mysql /usr/local/mysql-5.7.11
chown -R mysql.mysql /usr/local/mysql
chgrp -R mysql /usr/local/mysql-5.7.11
4.安裝和初始化資料庫
cd /usr/local/mysql/
cp -a ./support-files/my-default.cnf /etc/my.cnf
sudo rm /etc/init.d/mysqld
cp -a ./support-files/mysql.server /etc/init.d/mysqld
cd bin/
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
mysql (此時如果出現ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock',請檢查my.cnf中socket = /var/lib/mysql/mysql.sock行是否被註釋)
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 看第5步
/etc/init.d/mysqld restart
Shutting down MySQL.. [ OK ]
Starting MySQL... [ OK ]
#開機啟動
chkconfig --level 35 mysqld on
5.初始化密碼
mysql5.7會生成一個初始化密碼,而在之前的版本首次登陸不需要登入。
shell> cat /root/.mysql_secret
***
mysql -uroot -p
Enter password: ***
ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
kill mysql pid
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables &
mysql
mysql> select user,host,password_expired from mysql.user;
+-----------+-----------+------------------+
| user | host | password_expired |
+-----------+-----------+------------------+
| root | localhost | Y |
| mysql.sys | localhost | N |
+-----------+-----------+------------------+
2 rows in set (0.00 sec)
mysql> update mysql.user set password_expired='N' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update mysql.user set authentication_string=password('root') where user='root' and Host = 'localhost';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
mysql -hlocalhost -uroot -proot
哈 大功告成!!
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
(32位的下載 wget 'http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.16-linux-glibc2.5-i686.tar.gz')
sudo tar -zxvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gzsudo cp -r mysql-5.7.11-linux-glibc2.5-x86_64 /usr/local/
cd /usr/local
sudo mv mysql-5.7.11-linux-glibc2.5-x86_64/ mysql-5.7.11
2.建立軟連結
sudo ln -s mysql-5.7.11 mysql
3.建立mysql使用者和修改軟體的許可權
sudo -s
useradd -r -M -s /sbin/nologin mysql
chown -R mysql.mysql /usr/local/mysql-5.7.11
chown -R mysql.mysql /usr/local/mysql
chgrp -R mysql /usr/local/mysql-5.7.11
4.安裝和初始化資料庫
cd /usr/local/mysql/
bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --必須在mysql根目錄安裝mysql,否則出錯
(有可能會會報錯/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory 這個時候yum install libaio即可
或者執行bin/mysqld –initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --defaults-file=/etc/my.cnf
)
sudo rm /etc/my.cnfcp -a ./support-files/my-default.cnf /etc/my.cnf
sudo rm /etc/init.d/mysqld
cp -a ./support-files/mysql.server /etc/init.d/mysqld
cd bin/
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
mysql (此時如果出現ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock',請檢查my.cnf中socket = /var/lib/mysql/mysql.sock行是否被註釋)
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 看第5步
/etc/init.d/mysqld restart
Shutting down MySQL.. [ OK ]
Starting MySQL... [ OK ]
#開機啟動
chkconfig --level 35 mysqld on
5.初始化密碼
mysql5.7會生成一個初始化密碼,而在之前的版本首次登陸不需要登入。
shell> cat /root/.mysql_secret
***
mysql -uroot -p
Enter password: ***
ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
kill mysql pid
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables &
mysql
mysql> select user,host,password_expired from mysql.user;
+-----------+-----------+------------------+
| user | host | password_expired |
+-----------+-----------+------------------+
| root | localhost | Y |
| mysql.sys | localhost | N |
+-----------+-----------+------------------+
2 rows in set (0.00 sec)
mysql> update mysql.user set password_expired='N' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update mysql.user set authentication_string=password('root') where user='root' and Host = 'localhost';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
mysql -hlocalhost -uroot -proot
哈 大功告成!!