| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
9年前发布

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

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用户是没有被设置密码的。首先来设置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

然后,测试一下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</span>


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

直接敲

[root@sample~]# mysql -u root即可。


3. 安装MySQL Workbench

在这之前,确保你的电脑已安装


在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、开启端口

      方法一:

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

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

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

       方法二:

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

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

2、关闭端口

     方法一:

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

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

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

       方法二:

       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文件,(已验证)的是我操作过的,也是必须的。

来自:http://blog.csdn.net/chuck_0430/article/details/42974071

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1421897342203.html
MySQL CentOS