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 Files\MySQL\MySQL Server 5.6\bin>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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM