国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > 数据库 > 数据库应用 > centOS6.5下的MySQL的安装与配置

centOS6.5下的MySQL的安装与配置

来源:程序员人生   发布时间:2015-01-29 09:07:37 阅读次数:4691次

centOS6.5下的MySQL的安装与配置


1. SSH Secure Shell Client

首先,安装SSH Secure Shell Client,这是1款连接远程Linux系统的工具,简称SSH客户端。

在Linux主机上设置好ip地址和端口号以后,打开SSH Client,点击Quick Connect,填写远程服务的ip地址,用户名(1般默许为root),和端口号。

进入系统后,出现 Add Profile,可以再里面输入1个名称作为标识,相当于以后都无需使用用户名登录的快捷方式。


2. MySQL 

1、安装

<span style="font-size:12px;">[root@sample ~]# yum -y install mysql-server  // 安装MySQL [root@sample ~]# yum -y install php-mysql  // 安装php-mysql </span>

2、启动

<span style="font-size:12px;">[root@sample ~]# /etc/rc.d/init.d/mysqld start  //启动MySQL服务 Initializing MySQL database:      [ OK ] Starting MySQL:        [ OK ] </span>

3、为root用户设置密码

MySQL在刚刚被安装的时候,它的root用户是没有被设置密码的。首先来设置MySQLroot密码。


[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


然后,测试1下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


1旦设置密码成功以后,以后再登录使用就不用设置密码了

直接敲

[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://blog.csdn.net/ljx211520/article/details/6886134

1、开启端口

      方法1:

         /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT   写入修改

         /etc/init.d/iptables save   保存修改

        service iptables restart    重启防火墙,修改生效

       方法2:

       vi /etc/sysconfig/iptables  打开配置文件加入以下语句:

       -A INPUT -p tcp -m state --state NEW -m tcp --dport3306 -j ACCEPT   重启防火墙,修改完成

2、关闭端口

     方法1:

         /sbin/iptables -I INPUT -p tcp --dport3306 -j DROP   写入修改

         /etc/init.d/iptables save   保存修改

        service iptables restart    重启防火墙,修改生效

       方法2:

       vi /etc/sysconfig/iptables  打开配置文件加入以下语句:

       -A INPUT -p tcp -m state --state NEW -m tcp --dport3306 -j DROP   重启防火墙,修改完成 

3、查看端口状态

      /etc/init.d/iptables status


在设置完防火墙以后,1定要重启防火墙

service iptables restart



最后附上MySQL的安装和配置的.doc文件,(已验证)的是我操作过的,也是必须的。





生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------

上一篇 Libgdx1.5.3发布

下一篇 RGB灯WS2812B

分享到:
------分隔线----------------------------
关闭
程序员人生