mysql配置文件位置:vim /etc/my.cnf
詳細配置文件的模塊(可作為模板直接復制)
配置文件說明表:
項目 | 說明 |
---|---|
port | 監聽的端口; |
socket | 監聽的socket位置; |
skip-locking | 過濾lock,有些情況會有鎖,為了考慮速度可以過濾掉鎖; |
key_buffer_size | 索引塊的緩沖區,和內存有關系,增加大小可以增加索引速度; |
max_allowed_packet | 允許最大包,和mysql的web管理工具 導入數據包有關; |
table_open_cache | 所有的線程打開表的數量; |
sort_buffer_size | 排序的 緩沖區大小; |
read_buffer_size | 讀取Mysql數據的緩沖區; |
read_rnd_buffer_size | 隨機讀數據的緩沖區; |
myisam_sort_buffer_size | myisam搜索引擎的排序緩存區大小 ,mysql 有兩個搜索引擎 還有一個是 innodb; |
thread_cache_size | 線程緩存, 和CPU核數有關系,按照CPU 核數大小設置; |
query_cache_size | 查詢的緩存大小,查詢結果緩存在內存中 下次查詢可以可以直接緩存中調用; |
thread_concurrency | 和CPU核數有關,最大并發線程數,正常值是CPU核數X2; |
【相關擴展配置參數】
客戶端保持在線的時間:mysql客戶端 無數據訪問的時候,會有一段時間保持在線;但mysql允許同時連接的客戶端數量是有限的;過多無數據訪問客戶端在線會占用資源,影響mysql性能;這里可以手動設置無數據訪問客戶端保持在線的時長,以發揮mysql的最大傳輸性能;單位為秒 主配置文件中增加以下參數:(這里wait timeout
需要與interactive_timeou
配合使用;) interactive_timeout=8
wait timeout=8
這里設置的是保持客戶端在線時長8秒;
log-bin
配置二進制日志 和server-id
可以自行查詢資料了解。
long_query_time
設置多長時間記錄一次慢查詢日志,單位為秒;log_solw_queries
定義慢查詢日志位置;
使用root賬戶登錄mysql【默認是沒有密碼的】
[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>創建root密碼:
創建密碼:mysqladmin -uroot passWord 'chen1992'
使用root賬戶登錄mysql【-p后面跟密碼】:mysql -pchen1992
修改root的密碼:mysqladmin -uroot -pchen1992 password '1234qwer'
重置root密碼:(正常在忘記密碼的情況下使用)
編輯mysql配置文件:vim /etc/my.cnf
在配置文件中添加(不去授權)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; 查看相關信息,可以查看加過密的密碼等密碼更新后將vim /etc/my.cnf
配置文件中的 skip-grant
刪除,重啟mysql 即可
本地登錄mysql:mysql -uroot -p1234qwer
遠程登錄mysql:mysql -uroot -h192.168.0.106 -P3306 -p1234qwer
【-u
賬戶 -h
地址 -P
端口 -p
密碼】
mysql中對指定ip授權:grant all on *.* to 'root'@'192.168.0.105' identified by '1234qwer';
【這里的IP正常指的是客戶端IP】
查看是否授權成功的方法:
use mysql
select * from user where host='192.168.0.106'/G;
查看當前mysql用戶:select user();
多個mysql 本地登錄方法:mysql -uroot -S /tmp/mysql.sock -p1234qwer
新聞熱點
疑難解答