240
我爱毛绒绒~~~~~~~

MySQL语句总结

展示类-show

  • 显示数据库信息
show status;
  • 显示授权用户
show grants;
  • 展示表中字段
show columns from table;
  • 查看字符
show variables like '%char%';
  • 查看log-bin
show variables like '%log_bin%';
  • 查看binlog
show global variables like '%binlog%';
  • 查看数据库是否是严格模式
show variables like "%mode";
  • 查看数据库的链接数
show global variables like '%max_connect_errors%';

远程无法访问数据库

  • 查看数据库是否允许外网访问
select host from mysql.user where user='root';
  • 允许特定ip访问
create user 'root'@ip_address identified by 'some_pass';
grant all privileges on *.* to 'root'@'ip_address';
  • 允许所有ip访问
create user 'root'@'%' identified by 'some_pass';
grant all privileges on *.* to 'root'@'%';
  • 重新加载权限
flush privileges;

eg:https://cloud.tencent.com/developer/ask/49476

修改类

  • 修改数据库编码
  • 删除字段自增
alter table t1 modify id int not null;
  • 删除字段主键
alter table t1 drop primary key;
  • 修改联合主键
alter table t1 add primary key (id,name);

报错类

  • MySQLNonTransientConnectionException: Too many connections
  1. 永久修改-修改配置文件
    Windows:找到mysql的安装目录下的my.ini文件,将max_connections=100 ,改为max_connections=1000重 点:保存后重启mysql,一定要重启mysql才能生效
    Linux:找到mysql的安装目录,打开my.cnf文件在[mysqld]下面添加 max_connections=1000
  2. 临时修改
set global max_connect_errors=1000;
posted @ 2023-07-14 13:54  水开白  阅读(9)  评论(0编辑  收藏  举报