mysql管理员操作

mysql查帮助手册的技巧help 你的命令;比如 help create;

>>显示mysql中用户:select host,user from mysql.user;

>>>创建用户:mysql> create user 'zhangpeng'@'%' identified by 'oradt!@#&*(';

>>授权某个用户拥有某个数据库的任何权限

GRANT ALL PRIVILEGES ON stock_info.* TO 'test'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

创建数据库: mysql> create database stock_info default charset utf8 collate utf8_general_ci;

>>> 查看用户权限(显示用户权限): show grants from  用户名;  //show grants; 显示当前自己的权限

修改用户密码-> 首先进入命令行下, 以root用户登录,命令:mysql -uroot -p 回车 输入密码再回车;

              USER mysql;

              UPADTE user set  password=password('root') where user='root';

 mysql> FLUSH PRIVILEGES;//记得要这句话

>>> mysql优化表(回收表占用的闲置数据库空间),代码如何:

REPAIR TABLE `table_name` 修复表 
OPTIMIZE TABLE `table_name` 优化表

1.备份表结构(加上-d只备份表结构,不加此参数表结构、数据都备份):

C:Program FilesMySQLMySQL Server 5.6in>mysqldump -hlocalhost -P3308 -uroot
-p -d stock_info>F:/stock_info.sql
Enter password: ******

备份单个表的数据(表必须不存在):

create table st_pool_bak as SELECT  id,code FROM `st_pool` ;

mysql 查看数据库中所有表的记录数(总记录数)
use information_schema;
select table_name,table_rows from tables
where TABLE_SCHEMA = 'imora_scan'
order by table_rows desc;

MySQL LIMIT分页优化: SELECT * FROM `api_statistic` as apis
INNER JOIN (select id from api_statistic as ap2   limit 1410000,10 ) as c using(id);

Mysql查询表字段(列名):  select COLUMN_NAME from information_schema.COLUMNS where table_name = 'biz_employee_cards';
把字段合并成一条记录返回: select GROUP_CONCAT(COLUMN_NAME) from information_schema.COLUMNS where table_name = 'biz_employee_cards';
select COLUMN_NAME from information_schema.COLUMNS where table_name = 'your_table_name' and table_schema = 'your_db_name';
GROUP_CONCAT ( url SEPARATOR " @ " )
 
开启mysql远程访问端口: iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
service iptables save
原文地址:https://www.cnblogs.com/andydao/p/5447623.html