刪除修改
查詢元資料操作
表結構調整
許可權管理
字符集設定
資料匯入和匯出
匯入資料
遠端連線mysql
資料庫備份和複製
mysql 程序資訊
編碼集問題
insert into ticket_info (buyer_openid,ticket_date)
values
('000751a016bdbf8eb40e7a902f7153c6','2017-12-01'),
('000751a016bdbf8eb40e7a902f7153c6','2017-12-01');
ignore
unique索引或primary key重複,無視本條執行語句,即不執行。
insert ignore into `table_name` (`email`, `phone`, `user_id`)
values ('[email protected]', '99999', '9999');
replace
unique索引或primary key重複,刪除舊記錄,插入新記錄,返回受影響的行(刪除和插入行數的和)。
replace into `table_name`(`col_name`, ...) values (...);
on duplicate key update
unique索引或primary key重複,則執行舊行update。
insert into table (a, b, c) values (1, 2, 3), (4, 5, 6) on duplicate key update c=values(a)+values(b);
delete from user where user='test';
update user set password='test' where host='11.11.11.11' and user='11';
show variables
show databases
show tables[from db_name]
show tables like 'ticket%'
show create tables tbl_name
describe tablename
desc tablename
select columns from tablename
show full columns from tablename;
show index from tbl_name [from db_name]
alter table bulletin add citycode varchar(6) not null default 0;
alter table order_info modify column order_status int(4) not null comment '我的描述';
alter table 表名 change 原欄位名 新欄位名 字段型別 約束條件
alter table my_test_db change table_name_new table_name_old char(32) not null default '123';
alter table user drop column news;
create user 'user_name'@'11.11.11.11' identified by 'my_password';
flush privileges;
grant select on db.table to 'username'@'10.254.0.0/255.255.0.0' identified by '***';
grant select, insert on db_name.table_name to 'user_name'@'10.11.11.11';
grant all on *.* to user_name@'10.11.11.11'
grant all on *.* to user_name@'10.11.%' identified by '***';
show grants for 'user_name'@'100.76.%';
revoke update,select,delete on db_name.* from 'user_name'@'10.254.%';
執行grant授權命令,提示can』t find any matching row in the user table
我們建立使用者後,只是寫入了user表,但是並沒有及時寫入許可權表(grant table)。
執行 flush privileges命令,更新grant table,此時grant table裡有了我們剛插入的使用者,才能對它進行許可權修改:
flush privileges;
set names utf8;
show variables like「character_set_%
select * from user_info into outfile '/tmp/table.txt' character set utf8;
mysql -uroot -p123456 -e "select * from order_info" > /tmp/table.txt
mysql -uroot -p123456 -e "select * from order_info" > /tmp/table.xlsx
set names utf8;
load data local infile '/tmp/table.txt' into table user_info;
mysql -h 11.11.11.11 -p3306 -umyusernmae -pmypassword --default-character-set=utf8
mysqldump -h localhost -u root -p123456 guestbook > guestbook2-29.sql
create table mytbl_new like production.mytbl;
insert mytbl_new select * from production.mytbl;
show full processlist;
kill -9 id
mysql使用筆記
mysql安裝 bin mysqld initialize insecure user mysql basedir usr local mysql datadir usr local mysql data mkdir p var run mysqld chown mysql mysql var ru...
mysql使用筆記
建立資料庫 create database database name 刪除資料庫 drop database database name 建立表 最簡單的語法 create table userinfo id int uname varchar 40 address varchar 120 hob...
mysql使用筆記
mysql通用建表語句 create table if not exists stuinfo id int primary key auto increment,自增,主鍵非空唯一,會建立主鍵索引 stuname varchar 20 not null,非空 gender char 1 seat i...