centos7安裝mysql5.6成功
阿新 • • 發佈:2018-11-26
vim /etc/rc.local 2 新增service mysqld start
centos7下使用yum安裝mysql
CentOS7的yum源中預設好像是沒有mysql的。為了解決這個問題,我們要先下載mysql的repo源。
1. 下載mysql的repo源
$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
2. 安裝mysql-community-release-el7-5.noarch.rpm包
$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
安裝這個包後,會獲得兩個mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo。
3. 安裝mysql
$ sudo yum install mysql-server
根據步驟安裝就可以了,不過安裝完成後,沒有密碼,需要重置密碼。
4. 重置密碼
重置密碼前,首先要登入
$ mysql -u root
登入時有可能報這樣的錯:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2),原因是/var/lib/mysql的訪問許可權問題。下面的命令把/var/lib/mysql的擁有者改為當前使用者:
$ sudo chown -R openscanner:openscanner /var/lib/mysql
然後,重啟服務:
$ service mysqld restart
接下來登入重置密碼:
$ mysql -u root
mysql > use mysql;mysql > update user set password=password(‘123456‘) where user=‘root‘;mysql > exit;
5. 需要更改許可權才能實現遠端連線MYSQL資料庫
可以通過以下方式來確認:
root#mysql -h localhost -uroot -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 4.0.20a-debug
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql> use mysql; (此DB存放MySQL的各種配置資訊)
Database changed
mysql> select host,user from user; (檢視使用者的許可權情況)
mysql> select host, user, password from user;
+-----------+------+-------------------------------------------+
| host | user | password |
+-----------+------+-------------------------------------------+
| localhost | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| 127.0.0.1 | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| localhost | | |
+-----------+------+-------------------------------------------+
4 rows in set (0.01 sec)
由此可以看出,只能以localhost的主機方式訪問。
解決方法:
mysql> Grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
(%表示是所有的外部機器,如果指定某一臺機,就將%改為相應的機器名;‘root’則是指要使用的使用者名稱,)
mysql> flush privileges; (執行此句才生效,或者重啟MySQL)
Query OK, 0 rows affected (0.03 sec)
再次檢視。。
mysql> select host, user, password from user;
+-----------+------+-------------------------------------------+
| host | user | password |
+-----------+------+-------------------------------------------+
| localhost | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| 127.0.0.1 | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| localhost | | |
| % | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
+-----------+------+-------------------------------------------+
4 rows in set (0.01 sec)
博文地址:http://julyme.com/c/centos7下使用yum安裝mysql
個人部落格地址:http://julyme.com