mysql配置文件位置:vim /etc/my.cnf
詳細(xì)配置文件的模塊(可作為模板直接復(fù)制)
配置文件說(shuō)明表:
項(xiàng)目 | 說(shuō)明 |
---|---|
port | 監(jiān)聽的端口; |
socket | 監(jiān)聽的socket位置; |
skip-locking | 過(guò)濾lock,有些情況會(huì)有鎖,為了考慮速度可以過(guò)濾掉鎖; |
key_buffer_size | 索引塊的緩沖區(qū),和內(nèi)存有關(guān)系,增加大小可以增加索引速度; |
max_allowed_packet | 允許最大包,和mysql的web管理工具 導(dǎo)入數(shù)據(jù)包有關(guān); |
table_open_cache | 所有的線程打開表的數(shù)量; |
sort_buffer_size | 排序的 緩沖區(qū)大小; |
read_buffer_size | 讀取Mysql數(shù)據(jù)的緩沖區(qū); |
read_rnd_buffer_size | 隨機(jī)讀數(shù)據(jù)的緩沖區(qū); |
myisam_sort_buffer_size | myisam搜索引擎的排序緩存區(qū)大小 ,mysql 有兩個(gè)搜索引擎 還有一個(gè)是 innodb; |
thread_cache_size | 線程緩存, 和CPU核數(shù)有關(guān)系,按照CPU 核數(shù)大小設(shè)置; |
query_cache_size | 查詢的緩存大小,查詢結(jié)果緩存在內(nèi)存中 下次查詢可以可以直接緩存中調(diào)用; |
thread_concurrency | 和CPU核數(shù)有關(guān),最大并發(fā)線程數(shù),正常值是CPU核數(shù)X2; |
【相關(guān)擴(kuò)展配置參數(shù)】
客戶端保持在線的時(shí)間:mysql客戶端 無(wú)數(shù)據(jù)訪問(wèn)的時(shí)候,會(huì)有一段時(shí)間保持在線;但mysql允許同時(shí)連接的客戶端數(shù)量是有限的;過(guò)多無(wú)數(shù)據(jù)訪問(wèn)客戶端在線會(huì)占用資源,影響mysql性能;這里可以手動(dòng)設(shè)置無(wú)數(shù)據(jù)訪問(wèn)客戶端保持在線的時(shí)長(zhǎng),以發(fā)揮mysql的最大傳輸性能;單位為秒 主配置文件中增加以下參數(shù):(這里wait timeout
需要與interactive_timeou
配合使用;) interactive_timeout=8
wait timeout=8
這里設(shè)置的是保持客戶端在線時(shí)長(zhǎng)8秒;
log-bin
配置二進(jìn)制日志 和server-id
可以自行查詢資料了解。
long_query_time
設(shè)置多長(zhǎng)時(shí)間記錄一次慢查詢?nèi)罩荆瑔挝粸槊耄?code>log_solw_queries 定義慢查詢?nèi)罩疚恢茫?
使用root賬戶登錄mysql【默認(rèn)是沒(méi)有密碼的】
[root@CentOS-1 ~]# mysql -urootWelcome to the MySQL monitor. Commands end with ; or /g.Your MySQL connection id is 11Server version: 5.1.73-log MySQL Community Server (GPL)Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.mysql>創(chuàng)建root密碼:
創(chuàng)建密碼:mysqladmin -uroot passWord 'chen1992'
使用root賬戶登錄mysql【-p后面跟密碼】:mysql -pchen1992
修改root的密碼:mysqladmin -uroot -pchen1992 password '1234qwer'
重置root密碼:(正常在忘記密碼的情況下使用)
編輯mysql配置文件:vim /etc/my.cnf
在配置文件中添加(不去授權(quán))skip-grant
重啟mysql:/etc/init.d/mysqld restart
更新密碼:
mysql> use mysqlDatabase changedmysql> update user set password=password("1qaz2wsx") where user='root';mysql> select * from user where user='root'/G; 查看相關(guān)信息,可以查看加過(guò)密的密碼等密碼更新后將vim /etc/my.cnf
配置文件中的 skip-grant
刪除,重啟mysql 即可
本地登錄mysql:mysql -uroot -p1234qwer
遠(yuǎn)程登錄mysql:mysql -uroot -h192.168.0.106 -P3306 -p1234qwer
【-u
賬戶 -h
地址 -P
端口 -p
密碼】
mysql中對(duì)指定ip授權(quán):grant all on *.* to 'root'@'192.168.0.105' identified by '1234qwer';
【這里的IP正常指的是客戶端IP】
查看是否授權(quán)成功的方法:
use mysql
select * from user where host='192.168.0.106'/G;
查看當(dāng)前mysql用戶:select user();
多個(gè)mysql 本地登錄方法:mysql -uroot -S /tmp/mysql.sock -p1234qwer
新聞熱點(diǎn)
疑難解答
圖片精選