mysql -uroot -ppassword -e "set passowrd for root = passowrd('passowrd')" mysqladmin -uroot passowrd "NEWPASSWORD" 更改密碼
mysqladmin -uroot passowrd oldpassowrd "NEWPASSWORD"use mysql;update user set passowrd = PASSWORD('newpassword') where user = 'root';flush privileges; msyql 5.7以上版本修改默認密碼命令
alter user 'root'@'localhost' identified by 'root' 4.登陸MySQL數據庫 mysql -uroot -ppassword 5.查看當前數據庫的字符集 show create database DB_NAME; 6.查看當前數據庫版本 mysql -V mysql -uroot -ppassowrd -e "use mysql;select version();" 7.查看當前登錄的用戶 select user(); 8.創建GBK字符集的數據庫mingongge,并查看已建庫完整語句 create database mingongge DEFAULT CHARSET GBK COLLATE gbk_chinese_ci; 9.創建用戶mingongge,使之可以管理數據庫mingongge grant all on mingongge.* to 'mingongge'@'localhost' identified by 'mingongge'; 10.查看創建的用戶mingongge擁有哪些權限 show grants for mingongge@localhost 11.查看當前數據庫里有哪些用戶 select user from mysql.user; 12.進入mingongge數據庫 use mingongge 13.創建一innodb GBK表test,字段id int(4)和name varchar(16) create table test ( id int(4), name varchar(16) )ENGINE=innodb DEFAULT CHARSET=gbk; 14.查看建表結構及表結構的SQL語句 desc test;show create table test/G 15.插入一條數據“1,mingongge” insert into test values('1','mingongge'); 16.再批量插入2行數據 “2,民工哥”,“3,mingonggeedu” insert into test values('2','民工哥'),('3','mingonggeedu'); 17.查詢名字為mingongge的記錄 select * from test where name = 'mingongge'; 18.把數據id等于1的名字mingongge更改為mgg update test set name = 'mgg' where id = '1'; 19.在字段name前插入age字段,類型tinyint(2) alter table test add age tinyint(2) after id; 20.不退出數據庫,完成備份mingongge數據庫 system mysqldump -uroot -pMgg123.0. -B mingongge >/root/mingongge_bak.sql 21.刪除test表中的所有數據,并查看 delete from test;select * from test; 22.刪除表test和mingongge數據庫并查看 drop table test;show tables;drop database mingongge;show databases; 23.不退出數據庫恢復以上刪除的數據 system mysql -uroot -pMgg123.0. </root/mingongge_bak.sql 24.把庫表的GBK字符集修改為UTF8 alter database mingongge default character set utf8;alter table test default character set utf8; 25.把id列設置為主鍵,在Name字段上創建普通索引 alter table test add primary key(id);create index mggindex on test(name(16)); 26.在字段name后插入手機號字段(shouji),類型char(11) alter table test add shouji char(11);#默認就是在最后一列后面插入新增列 27.所有字段上插入2條記錄(自行設定數據) insert into test values('4','23','li','13700000001'),('5','26','zhao','13710000001'); 28.在手機字段上對前8個字符創建普通索引 create index SJ on test(shouji(8)); 29.查看創建的索引及索引類型等信息 show index from test;show create table test/G #下面的命令也可以查看索引類型 show keys from test/G 30.刪除Name,shouji列的索引 drop index SJ on test;drop index mggindex on test; 31.對Name列的前6個字符以及手機列的前8個字符組建聯合索引 create index lianhe on test(name(6),shouji(8)); 32.查詢手機號以137開頭的,名字為zhao的記錄(提前插入) select * from test where shouji like '137%' and name = 'zhao'; 33.查詢上述語句的執行計劃(是否使用聯合索引等) explain select * from test where name = 'zhao' and shouji like '137%'/G 34.把test表的引擎改成MyISAM alter table test engine=MyISAM; 35.收回mingongge用戶的select權限 revoke select on mingongge.* from mingongge@localhost; 36.刪除mingongge用戶 drop user migongge@localhost; 37.刪除mingongge數據庫 drop database mingongge 38.使用mysqladmin關閉數據庫 mysqladmin -uroot -pMgg123.0. shutdownlsof -i :3306 39.MySQL密碼丟了,請找回? mysqld_safe --skip-grant-tables & #啟動數據庫服務mysql -uroot -ppassowrd -e "use mysql;update user set passowrd = PASSWORD('newpassword') where user = 'root';flush privileges;" ?。?)MySQL運維基礎知識面試問答題 面試題001:請解釋關系型數據庫概念及主要特點? 關系型數據庫模型是把復雜的數據結構歸結為簡單的二元關系,對數據的操作都是建立一個或多個關系表格上,最大的特點就是二維的表格,通過SQL結構查詢語句存取數據,保持數據一致性方面很強大
面試題007:如何創建一個utf8字符集的數據庫mingongge? create database mingongge default character utf8 collate utf8_general_ci; 面試題008:如何授權mingongge用戶從172.16.1.0/24訪問數據庫。 grant all on *.* to mingongge@'172.16.1.0/24' identified by '123456'; 面試題009:什么是MySQL多實例,如何配置MySQL多實例? mysql多實例就是在同一臺服務器上啟用多個mysql服務,它們監聽不同的端口,運行多個服務進程,它們相互獨立,互不影響的對外提供服務,便于節約服務器資源與后期架構擴展 多實例的配置方法有兩種: 1、一個實例一個配置文件,不同端口 2、同一配置文件(my.cnf)下配置不同實例,基于mysqld_multi工具
[mysqld] wait_timeout = 600interactive_timeout=30#如果生產服務器不可隨便重啟可以使用下面的方法解決set global wait_timeout=600set global interactive_timeout=30; 面試題014:sort_buffer_size參數作用?如何在線修改生效? 在每個connection(session)第一次連接時需要使用到,來提訪問性能 set global sort_buffer_size = 2M 面試題015:如何在線正確清理MySQL binlog? MySQL中的binlog日志記錄了數據中的數據變動,便于對數據的基于時間點和基于位置的恢復 但日志文件的大小會越來越大,點用大量的磁盤空間,因此需要定時清理一部分日志信息 手工刪除:
首先查看主從庫正在使用的binlog文件名稱 show master(slave) status/G 刪除之前一定要備份 purge master logs before'2017-09-01 00:00:00'; #刪除指定時間前的日志 purge master logs to'mysql-bin.000001'; #刪除指定的日志文件 自動刪除: 通過設置binlog的過期時間讓系統自動刪除日志 show variables like 'expire_logs_days'; et global expire_logs_days = 30; #查看過期時間與設置過期時間