MySQL客户端登录(10)

客户端登陆
交互式登录
MySQL –h –u –p –P DBNAME –e “sql”
-u 是用户的意思 一般直接可以写成 –uroot 或者 –u MySQL
-h 是指主机IP的意思 –h192.168.1.120,设置用户可以远程访问才行
-p 是密码的意思,可以直接写密码-pP@ssw0rd 或者为了安全不写密码 –p
-P 是端口的意思,针对多实例的mylsq可以选择端口登录 –p3306
DNNAME 是指数据库名字,可以直接写数据库名称
-e 是用来执行语句的
[root@MySQL ~]# MySQL -h 192.168.1.120 -uroot -pP@ssw0rd -P3306 test001
MySQL客户端登录(10)
非交互式使用
-e
[root@MySQL ~]# MySQL -h 192.168.1.120 -uroot -pP@ssw0rd -P3306 -e "show databases;" >>/root/shell/test.sql
MySQL客户端登录(10)
其他
;和\g 代表一句语句书写完毕的意思
MySQL客户端登录(10)
\h或者\?是代表查看帮助
MySQL客户端登录(10)
MySQL客户端登录(10)
客户端登陆忘记密码怎么办

MySQL 5.7.6以后版本
编辑my.cnf文件
无论源码编译 二进制编译或者yum安装和rpm安装
添加
[MySQLd]
skip-grant-tables
[root@MySQLgeneric ~]# vi /etc/my.cnf
MySQL客户端登录(10)
重新启动MySQL服务
[root@MySQLsource ~]# service MySQLd restart
MySQL客户端登录(10)
登录MySQL数据库
[root@MySQLsource ~]# MySQL
MySQL客户端登录(10)
查看MySQL权限内容
MySQL> desc MySQL.user;
MySQL客户端登录(10)
MySQL> select user,host,authentication_string from MySQL.user;
MySQL客户端登录(10)
修改密码
MySQL> update MySQL.user set authentication_string=password('P@ssw0rd123') where user='root';
MySQL客户端登录(10)
修改回my.cnf文件并重新启动MySQL服务器
[root@MySQLsource ~]# vi /etc/my.cnf
MySQL客户端登录(10)
MySQL客户端登录(10)
登录数据库
[root@MySQLsource ~]# MySQL -uroot -pP@ssw0rd123
MySQL客户端登录(10)
MySQL5.7.5之前的版本
MySQL客户端登录(10)

上一篇:【转】linux内核调试技巧之一 dump_stack


下一篇:2020-11-29