mysql命令實踐 MySQL 常用命令行

2021-10-19 05:54:25 字數 1873 閱讀 4612

登入

mysql -h192.168.1.110 -uroot -ppassword

登出quit/exit

檢視資料庫

show databases;

使用者許可權

#新增grant select on db.table to 'user'@'host';

grant select,update on *.* to 'test'@'%';

#撤銷revoke all on *.* from 'test'@'%';

#檢視show grants;

show grants for user@localhost

#刪除使用者

delete from mysql.user where user='' and host='';

#設定密碼

update mysql.user set password=password('123456') where user='root';

#配置遠端連線

grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;

匯出mysqldump -u 使用者名稱 -p 資料庫名 > 資料庫名.sql

mysqldump -u root -p dbname > filepath.sql

#to export tofile(data only)

mysqldump -u [user]-p[pass]--no-create-db --no-create-info mydb > mydb.sql

#to export tofile(structure only)

mysqldump -u [user]-p[pass]--no-data mydb > mydb.sql

#to import todatabase

mysql -u [user]-p[pass] mydb < mydb.sql

匯入mysql> use dbname #切到要匯入的資料庫

mysql> source filepath.sql

變數檢視/修改

show variables like '%slow%';

set global slow_query_log= 'on';

show status like 'qca%';

#檢視sql中select條數

show status like 'com_sel%'; #顯示的是一次會話的值!

show global status like "com_select";

找回密碼?

1、kill -term mysqld

2、conf中加入skip-grant-tables

3、service mysqld restart

4、mysql -uroot -p

5、修改密碼

6、改回原配置並重啟

purge binary logs to 'mysql-bin.010';

purge binary logs before '2008-04-02 22:46:26';

清空表並使自增歸0

truncate table tablename

mac無法登陸

can't connect to mysql server on '127.0.0.1' (61)

stevenmacbookair:~ hobo$ sudo su -

stevenmacbookair:~ root# nohup /usr/local/mysql/bin/mysqld_safe &

[1] 464

exit

logout

stevenmacbookair:~ hobo$

mysql檢視mylog命令 mysql常用命令

連線mysql 1.登入mysql資料庫 mysql u使用者名稱 p密碼 示例 2.登入遠端主機的mysql mysql h遠端主機ip位址 u使用者名稱 p密碼 示例 注 建立使用者命令格式為 create user hehe 192.168.93.151 3.退出mysql命令 exit 修改...

mysql常使用的命令

登入資料庫 mysql uroot p 會提示你輸入密碼 i 登入修改資料庫的密碼 i set password for root localhost password newpass i 用mysqladmin i mysqladmin u root password newpass 如果root...

mysql生效命令 mysql常使用的命令

mysql uroot p 會提示你輸入密碼 登入修改資料庫的密碼 set password for root localhost password newpass 用mysqladmin mysqladmin u root password newpass 如果root已經設定過密碼,採用如下方法...