Mysql 客户端连接
默认情况下,安装好mysql的时候,都只是在本地登录;如果说哪一天我们的程序员,需要操作数据库中的某一张表,你不可能让他们ssh到服务器上,在mysql 去登录我们的数据库吧,所以,我们使用mysql的客户端工具,mysql的数据库客户端程序有很多
以我目前使用是为列,讲述一下如何能让客户端正确的连接上我的mysql server
步骤一:先正常安装mysql,启动我们的程序,使用用户名能登录,这一步是先确定本机能登录
[root@mail ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4217
Server version: 5.5.19-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
如果说,默认的我们不做任何操作的话,用客户端连接程序的话
如果防火墙端口3306没有开启,会提示
2003 不能连接mysql的服务器
开放mysql的端口
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
重启防火墙
之后再尝试连接
之后会提示我们1130 错误,不被允许连接,
这样的话,我们就在服务器上进行mysql的设置
mysql> select * from user where user='root';
结果:| localhost | root | *566837CC61953EA120B57AA8D9A451BD48EEDBDC | Y
只是其中的一个结果
也就是说,当我们搭建好一个mysql数据库时,默认的权限只是允许localhost端去登录、操作数据库中的表
这样的话,只能去操作我们的mysql,来update下表中的记录,让其允许客户端ip的连接
update user set host='%' where user='root';
执行这样一条语句
后
Flush privileges
之后再select一下
mysql> select host,user from user;
+-----------------------+---------+
| host | user |
+-----------------------+---------+
| % | root |
默认的话,第一行是%,%代表的是全部的IP
这样的话,可以先测试一下,是不是可以连接上,要是可以的话,我们就设置下客户端
[root@mail ~]# mysql -h 192.168.20.202 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 181
Server version: 5.1.42-log Source distribution
Ok的
下面设置客户端的连接
我使用的客户端是Navicat Premium
连接名可以自己定义
端口是你mysql的访问端口,默认是3306
用户名是你登录mysql数据库的用户名、密码
可以测试一下,测试ok
那连上去,就可以对数据库进行操作了