首页 > 代码库 > mysql远程登录问题

mysql远程登录问题

 [Q1] 解决mysql远程登录

一、确认服务器端口号开放
1、确认3306端口是否对外开放

ubuntu@ubuntu:~$ netstat -an | grep 3306tcp0 0 127.0.0.1:3306  0.0.0.0:*   LISTEN


此处3306端口只监听本地的(127.0.0.1)连接,修改/etc/mysql/my.cnf中的bind-address,注释掉或者改成指定的IP
二、授权远程连接用户<br>
1、登录:

mysql -uroot -pxxxx

2、授权

grant all privilege on [database].[table] to [user]@[ip] identified by [password]mysql>grant all on *.* to user_name@‘%‘ identified by ‘user_password‘;

database:授权的数据库名,所有的数据库用匹配符`*`<br>
table:授权的表名,所有的表用匹配符`*`<br>
user:授权的用户名<br>
ip:授权的ip地址,例如 xxx.xxx.xxx.xxx 

password:授权用户名的密码,例如 xxxxxx 
3、刷新授权或者mysql重启

flush privilegesudo /etc/init.d/mysql restart

---
[Q2]mysql 命令导入csv

select * from test_info   into outfile /tmp/test.csv   fields terminated by , optionally enclosed by " escaped by "   lines terminated by \r\n; 

 

mysql远程登录问题