2.登陆mysql,修改mysql库的一个表(user)
(1)use mysql (切换到mysql库)
use +库名 表示切换到该库下
(2)执行修改命令
(可以看出我们的密码是经过加密的)
修改命令:
update user set password=password('123456') where user='root';
password()是mysql的一个加密函数;
3.退出mysql状态:exit
修改配置文件
vim /etc/my.cnf
在[mysqld]中删除 skip-grant
4.重启服务:
/etc/init.d/mysqld restart
{重置密码的步骤:
1.修改配置文件vim/etc/my.cnf -->添加skip-grant-->重启服务/etc/init.d/mysqld restart
2.进到mysql下-->use mysql切换库-->修改update user set password=password('123456') where user='root';
3.修改配置文件vim/etc/my.cnf -->删除skip-grant-->重启服务/etc/init.d/mysqld restart
连接MySQL
连接方式:
1.连接本机的mysql
mysql -uroot -p123456
mysql -u用户名 -p'用户密码'
2.链接远程的mysql(tcp/ip)
mysql -uroot -p123456 -h127.0.0.1 -P3306
mysql -u用户名 -p'用户密码' -h目标ip -P监听的端口
3.使用socket连接:
mysql -uroot -p123456 -S/tmp/mysql.sock
mysql -u用户名 -p'用户密码' -S监听的socket
4.mysql -uroot -p'123456' -e "show databases"
(-e 这个多数用在shell脚本)
mysql -uroot -p123456 相当于 mysql -uroot -p123456 -S/tmp/mysql.sock
因为没有指定ip 的时候就会默认使用socket去连接()默认的sock就是/tmp/mysql.sock。
MySQL常用命令(需要用分号终结‘;’)
1. 查询库 show databases;
2. 切换库 use mysql;
3.查看库里的表 show tables;
4. 查看表里的字段 desc tb_name(表名);
desc user;
5.查看建表语句 show create table tb_name\G;
show create table user\G;
12.查看各参数 show variables; show variables like 'max_connect%';
13. 修改参数 set global max_connect_errors=1000;
(仅在当前内存生效,若要永久生效则修改配置文件vim /etc/my.cnf)
14.查看队列 show processlist; show full processlist;
(加上 full 会显示更全面的内容,这个命令常用)