centOS6.5下的MySQL的安装与配置(一)

2015-01-23 21:54:02 · 作者: · 浏览: 6

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

一、安装

[root@sample ~]# yum -y install mysql-server  // 安装MySQL
[root@sample ~]# yum -y install php-mysql     // 安装php-mysql


二、启动

[root@sample ~]# /etc/rc.d/init.d/mysqld start  //启动MySQL服务
Initializing MySQL database:      [ OK ]
Starting MySQL:                  [ OK ]


三、为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为例 该方法转自:http://bl