1.首先安裝wget命令:mysql
yum -y install wgetsql
2.下載mysql數據庫
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpmide
3.安裝mysql-community-release-el7-5.noarch.rpm包測試
rpm -ivh mysql-community-release-el7-5.noarch.rpmspa
4.安裝mysqldebug
yum install mysql-server
server
以下圖,表示安裝成功
blog
5.安裝完畢後登陸mysql修改密碼get
mysql -u root
會有以下報錯
6.把/var/lib/mysql的擁有者改成當前用戶:
sudo chown -R root:root /var/lib/mysql
7.啓動mysql: systemctl start mysqld
設置開機啓動:systemctl enable mysqld
systemctl daemon-reload
8.修改密碼
$ mysql -u root
mysql > use mysql;
mysql > update user set password=password(‘123456‘) where user=‘root‘;
mysql > exit;
9.須要更改權限才能實現遠程鏈接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)
10.用第三方軟件測試鏈接(切記:關閉防火牆)