mysql常用命令彙總介紹
設定更改mysqlroot密碼
首次進入mysql資料庫,
!
可以將mysql絕對路徑加入到環境變數中,
還可以設定開機載入,
重新載入環境變數讓mysql生效
重新登入 mysql -uroot 即可
給mysql新增密碼
重新登入驗證,
修改密碼
重新登入驗證,驗證成功
重置密碼,修改配置檔案,跳過授權
重啟mysql服務,使用root使用者驗證不需要密碼
進去修改密碼檔案
update user set password=password('aminglinux') where user='root';
退出後修改my.conf
刪掉上面的跳過授權檔案
重啟mysqld 服務
重新進入mysql驗證
連線mysql
方式1 :使用tcpip協議ip:埠,適用於遠端的ip,這個例子就是本機做實驗
方式2:使用socket(前提是my.conf裡面配置有sock),這種情況只適合在本機使用。
方式3:使用命令列,適合與shell指令碼中
mysql常用命令
查詢庫 show databases;
切換庫 use mysql;
檢視庫裡的表 show tables;
查看錶裡的欄位 desc tb_name;
檢視建表語句 show create table tb_name\G;
檢視當前使用者 select user();
檢視當前使用的資料庫 select databsase();
建立庫 create database db1;
建立表 use db1; create table t1(id
int(4),name
char(40)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
刪除表 drop table t1;
檢視當前資料庫版本 select version();
檢視資料庫狀態 show status;
檢視各引數 show variables; 通配show variables like 'max_connect%';
修改引數 set global max_connect_errors=1000;也可以在/etc/my.conf中修改
檢視佇列 show processlist; show full processlist;