Linux上通过mysql命令访问MySQL数据库时常见问题汇总

Linux上通过mysql命令访问MySQL数据库时常见问题汇总

1)创建登录账号

#创建用户并授权

#允许本地访问

create user 'test'@'localhost' identified by '123456';

#允许外网访问

create user 'test'@'%' identified by '123456';

#grant 权限  on 数据库.* to '用户名'@'登录主机' identified by '密码';

扫描二维码关注公众号,回复: 1614919 查看本文章

#原始密码为:123456 加密后的密码为:*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9

grant all privileges on *.* to 'root'@'%' identified by password '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' with grant option;

#用户通过本地IP访问数据库

grant all privileges on *.* to 'test'@'localhost' identified by '123456';

#用户通过外网IP访问数据库

grant all privileges on *.* to 'test'@'%' identified by '123456';

#刷新权限

flush privileges;

#创建数据库

create database 数据库名;

#删除数据库

drop database 数据库名;

#删除表

drop table 表名;

#删除用户及权限

drop user '用户名'@'localhost';

drop user '用户名'@'%';

#刷新权限

flush privileges;

2)正常登录的命令

mysql -utest -p123456 -P3306 -h192.168.48.129

3)mysql命令找不到

[roadexam@centos7 src]$ mysqls -utest -p123456 -P3306 -h192.168.48.129

bash: mysqls: command not found

4)参数u大写ERROR 1064 (42000)...use near 'st' at line 1

[roadexam@centos7 src]$ mysql -Utest -p123456 -P3306 -h192.168.48.129

mysql: [Warning] Using a password on the command line interface can be insecure.

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'st' at line 1

5)用户名错误 ERROR 1045 (28000)...Access denied

[roadexam@centos7 src]$ mysql -utest1 -p123456 -P3306 -h192.168.48.129

mysql: [Warning] Using a password on the command line interface can be insecure.

ERROR 1045 (28000): Access denied for user 'test1'@'192.168.48.129' (using password: YES)

6)P为大写或和密码之间有空格或密码错误 ERROR 1045 (28000)...Access denied

[roadexam@centos7 src]$ mysql -utest -p 123456 -P3306 -h192.168.48.129

Enter password:

ERROR 1045 (28000): Access denied for user 'test'@'192.168.48.129' (using password: NO)

[roadexam@centos7 src]$ mysql -utest -P123456 -P3306 -h192.168.48.129

ERROR 1045 (28000): Access denied for user 'test'@'192.168.48.129' (using password: NO)

[roadexam@centos7 src]$ mysql -utest -p1234567 -P3306 -h192.168.48.129

mysql: [Warning] Using a password on the command line interface can be insecure.

ERROR 1045 (28000): Access denied for user 'test'@'192.168.48.129' (using password: YES)

7)端口号不对 ERROR 2003 (HY000):Can't connect to MySQL...(111)

[roadexam@centos7 src]$ mysql -utest -p123456 -P3307 -h192.168.48.129

mysql: [Warning] Using a password on the command line interface can be insecure.

ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.48.129' (111)

8)连接数据库的地址不对 ERROR 2003 (HY000): Can't connect to MySQL...(113)

[roadexam@centos7 src]$ mysql -u test -p123456 -P 3306 -h 192.168.48.121

mysql: [Warning] Using a password on the command line interface can be insecure.

ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.48.121' (113)

9)地址中包含端口号信息 ERROR 2005 (HY000): Unknown MySQL...(0)

[roadexam@centos7 src]$ mysql -u test -p123456 -P 3306 -h 192.168.48.129:3306

mysql: [Warning] Using a password on the command line interface can be insecure.

ERROR 2005 (HY000): Unknown MySQL server host '192.168.48.129:3306' (0)

猜你喜欢

转载自www.cnblogs.com/NiceTime/p/9193246.html