centOS6.5下的MySQL的安裝與配置,centos6.5mysql
centOS6.5下的MySQL的安裝與配置
1. SSH Secure Shell Client
首先,安裝SSH Secure Shell Client,這是一款串連遠程Linux系統的工具,簡稱SSH用戶端。
在Linux主機上設定好ip地址和連接埠號碼之後,開啟SSH Client,點擊Quick Connect,填寫遠程服務的ip地址,使用者名稱(一般預設為root),和連接埠號碼。
進入系統後,出現 Add Profile,可以再裡面輸入一個名稱作為標識,相當於以後都無需使用使用者名稱登入的捷徑。
2. MySQL
一、安裝
<span style="font-size:12px;">[root@sample ~]# yum -y install mysql-server // 安裝MySQL[root@sample ~]# yum -y install php-mysql // 安裝php-mysql</span>
二、啟動
<span style="font-size:12px;">[root@sample ~]# /etc/rc.d/init.d/mysqld start //啟動MySQL服務Initializing MySQL database: [ OK ]Starting MySQL: [ OK ]</span>
三、為root使用者佈建密碼
MySQL在剛剛被安裝的時候,它的root使用者是沒有被設定密碼的。首先來設定MySQL的root密碼。
[root@sample ~]# mysql -u root ←用root使用者登入MySQL伺服器
Welcome to the MySQL monitor. Commands end with ;or \g.
Your MySQL connection id is 2 to server version: 4.1.20
Type 'help;' or '\h' forhelp. Type '\c' to clear the buffer.
mysql> select user,host,password from mysql.user; ← 查看使用者資訊
+------+------------------------------+---------------+
| user | host | password |
+------+------------------------------+---------------+
| root | localhost | | ← root密碼為空白
| root | sample.centospub.com | | ← root密碼為空白
| | sample.centospub.com | |
| | localhost | |
+------+------------------------------+---------------+
4 rows in set (0.00 sec)
mysql> set password for root@localhost=password('在這裡填入root密碼'); ← 設定root密碼
Query OK, 0 rows affected (0.01 sec)
mysql> set password for root@'sample.centospub.com'=password('在這裡填入root密碼'); ← 設定root密碼
Query OK, 0 rows affected (0.01 sec)
mysql> select user,host,password from mysql.user; ← 查看使用者資訊
+------+-----------------------------------+--------------------------------+
| user | host | password |
+------+-----------------------------------+--------------------------------+
| root | localhost | 19b68057189b027f | ←root密碼被設定
| root | sample.centospub.com | 19b68057189b027f | ←root密碼被設定
| | sample.centospub.com | |
| | localhost | |
+------+-----------------------------------+--------------------------------+
4 rows in set (0.01 sec)
mysql> exit ← 退出MySQL伺服器
Bye
然後,測試一下root密碼有沒有生效。
[root@sample~]# mysql -u root ← 通過空密碼用root登入
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password:NO) ← 出現此錯誤資訊說明密碼設定成功
[root@localhost ~]# mysql -u root -h sample.centospub.com ← 通過空密碼用root登入
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password:NO) ← 出現此錯誤資訊說明密碼設定成功
[root@sample ~]# mysql-u root -p ← 通過密碼用root登入
Enter password: ← 在這裡輸入密碼
Welcome to the MySQL monitor. Commands end with ; or \g. ← 確認用密碼能夠成功登入
Your MySQL connection id is 5 to server version: 4.1.20
Type 'help;' or '\h' forhelp. Type '\c' to clear the buffer.
mysql> exit
Bye
[root@sample ~]# mysql -u root -hsample.centospub.com -p ←通過密碼用root登入
Enter password: ← 在這裡輸入密碼
Welcome to the MySQL monitor. Commands end with ; or \g. ← 確認用密碼能夠成功登入
Your MySQL connection id is 6 to server version: 4.1.20
Type 'help;' or '\h' forhelp. Type '\c' to clear the buffer.
mysql> exit ← 退出MySQL伺服器
Bye
一旦設定密碼成功之後,以後再登入使用就不用設定密碼了
直接敲
[root@sample~]# mysql -u root即可。
3. 安裝MySQL Workbench
在這之前,確保你的電腦已安裝
- Microsoft .NET Framework 4 Client Profile
- Visual C++ Redistributable for Visual Studio 2013
在MySQL Workbench成功安裝後,即可串連ip和連接埠。
需要注意的是,如果你Linux中的相應連接埠的防火牆沒有關閉,是無法串連的。
以下是關於防火牆的Linux命令:
(1)永久生效,重啟後不複原 (不推薦)
開啟: chkconfig iptables on
關閉:chkconfig iptables off
(2)即時生效,重啟後複原(存在安全隱患)
開啟: service iptables start
關閉: service iptables stop
(3)針對某個連接埠的,以3306為例 該方法