-
登录命令
mysql -h localhost -u root -p
-
显示数据库、表、表结构
show databases;
show tables; desc 表名;
-
查看所有连接
show proccesslist;
-
修改登录密码
update user set authentication_string = password('123456') where user = 'root';
-
忘记密码后重置密码
- vim /etc/my.cnf
- 尾部增加 skip-grant-tables 关闭密码登录检测权限
- systemctl restart mysqld
- 登录mysql -u root
- use mysql;
- select host,user,authentication_string from user;
- 修改密码:update user set authentication_string = password('123456') where user = 'root';
- vim /etc/my.cnf 注释尾部内容
- systemctl restart mysqld
- mysql -u root -p
-
mysql 8.0版本直接将查询缓存的整块功能删掉了,也就是说8.0开始彻底没有这个功能了。
-
修改表中的字段类型
alter table 表名 modify 字段名 类型;
-
增加主键字段
alter table table1 add id int unsigned not Null auto_increment primary key
-
修改主键
ALTER TABLE `test2` DROP PRIMARY KEY ,ADD PRIMARY KEY ( `id` )
-
修改表字段是否为空
alter table 表名称 modify 字段名称 字段类型 [是否允许非空];
-
删除表字段
ALTER TABLE mytable DROP 字段时名;
-
mysql启动报错MySql server startup error 'The server quit without updating PID file '
1.可能是配置文件修改有问题 2.可能是存在重启启动的mysqld线程,考虑杀死线程