MySQL数据库

命令:

查看 MySQL 的安装路径:

1. select @@basedir as basePath from dual;
2. show variables like "%char%";
   - character_sets_dir 这个就是安装路径。

查看 MySQL 的data路径:

1. select @@datadir as dataPath from dual;
2. show variables Like '%datadir%';

命令行连接数据库:

mysql -h localhost -u 用户名(mysql 默认用户root) -p(这个是要输入密码带的选项)
Ps: 该命令为 mysql -h localhost -u root -proot。这里的 -p 后面的 root 就是密码。此处特别注意 -p 和密码之间没有空格。如果出现空格,系统将不会把后面的字符串当成密码来对待

切换当前数据库: use 数据库名;

查看所有数据库:

1.show databases;
2.select schema_name from information_schema.schemataG

查看所有用户: select user,host from mysql.user;

查看mysql数据库的运行状态: status;

查看当前数据库:

  1. select database();
  2. show tables; 命令后,查看 Tables_in_数据库名
  3. status; 命令后,查看 Current database: 后面就是当前数据库。

查看表结构: desc table_name;

查询数据库连接: show full processlist;

不连接数据库查询数据库连接: mysqladmin -uroot -p  processlist

查看最大连接数: show status like'%Max_used_connections%';

当前连接数: show status like '%Threads_connected%';

表锁定: show status like '%table_lock%';

行锁定: show status like 'innodb_row_lock%';

查询缓存情况: show status like '%qcache%';

查询缓存: show variables like "%query_cache%";

查看查询缓存使用状态值: show status like 'Qcache%';

查看MySQL binlog模式: show variables like "%binlog%";

由于客户没有正确关闭连接已经死掉,已经放弃的连接数量: show status like 'Aborted_clients';

查看最大连接数量: show variables like '%max_connections%';

查看超时时间: show variables like '%timeout%';

查看日志是否启动: show variables like 'log_%';

格式化输出乱的查询: 在 ; 前加上 G

用户和权限:

查看当前mysql用户权限: show grants;

查看某个用户的权限: show grants for 用户名@主机;

MySQL用户创建: create user '用户名'@'主机' identified by '密码';

赋予 MySQL 用户权限:

grant {PRIVILEGES} on *.* to '用户名'@'host';
PRIVILEGES 代表权限,具体要赋予那些权限,自己查看MySQL 文档
*.* 代表所有数据库所有表, 如果是特定的数据库,例如: test.*

你可能感兴趣的:(mysql)