mysql常用操作總結

2021-09-01 21:47:51 字數 1662 閱讀 7853

設定mysql 是否區分表名大小寫:

開啟安裝目錄下的my.ini檔案,在[mysqld]下面加上這句話:

lower_case_table_names=0
設為0表示表名區分大小寫,設為1表示表名不區分大小寫

例如:檢視 select * from user 的執行時間,需要:

1.開啟profile:

set profiling=1;
2.執行sql語句:

select * from user
show profiles;
duration就是執行時間。

解決 連線mysql的時候,使用localhost可以連線,使用ip不能連線:

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

比如:grant all privileges on *.* to root@'%' identified by 'root';

就會發現mysql資料庫的user表中增加了一條記錄。而且可以使用ip連線了。

刪除表中重複的記錄(除了id之外的字段相同的記錄表示重複):

步驟一.查詢出要刪除的記錄:

select t1.* from mytable t1 where t1.id > (

select min(t2.id) from mytable t2

where t1.column1=t2.column1 and t1.column2=t2.column2 and t1.column3=t2.column3...

)

步驟二.刪除記錄:

直接這樣是不行的:

delete t1 from mytable t1 where t1.id > (

select min(t2.id) from mytable t2

where t1.column1=t2.column1 and t1.column2=t2.column2 and t1.column3=t2.column3...

)

需要這樣才行:(外面巢狀一下)

delete from mytable where id in (

select id from (

select t1.* from mytable t1 where t1.id > (

select min(t2.id) from mytable t2

where t1.column1=t2.column1 and t1.column2=t2.column2 and t1.column3=t2.column3...

)) as a

)

命令列備份mysql資料庫:

mysqldump -u root -proot test > e:/test.bak

恢復資料庫:

mysql -u root -proot test < e:/test.bak

查詢id自增結果,即執行最近的一次插入時,id的值:

select last_insert_id()

MySQL 常用操作總結

前兩周用php5.5 mysql5.6 搭建了幾個demo,期間從頭開始學習了php,然後sql命令也都忘得差不多了,現查現用。這裡總結一下自己用到的mysql命令吧。注 mysql中欄位名字 資料庫,表,字段 不區分大小寫,sql語句也不區分大小寫。1.檢視現有的資料庫 show database...

mysql常用操作指令總結

總結 1 資料庫操作 建立庫 create database db name 查詢庫 show databases 顯示所有的資料庫 show create databases db name 顯示特定的資料庫 刪除庫 drop database db name 修改庫 alter database...

my sql常用操作

1.grant allprivilegeson tomonty localhost identified by something with grant option monty 可以從任何地方連線伺服器的乙個完全的超級使用者,但是必須使用乙個口令 something 做這個。注意,我們必須對 mo...