mysql一些操作个人备忘(持续更新)
生活随笔
收集整理的這篇文章主要介紹了
mysql一些操作个人备忘(持续更新)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
安裝mysql數據庫目錄
1./usr/local/mysql/bin/mysql_install_db --user=mysql --datadir=/home/mysql/var ##指定安裝后的數據目錄mysql 啟動/關閉
1./usr/local/mysql/bin/mysqld_safe --defaults-file=/home/mysql/.my.cnf --user=mysql & #啟動 2./usr/local/mysql/bin/mysqladmin --defaults-file=/home/mysql/.my.cnf shutdown -uroot -p #關閉更改root密碼
1.update user set password=password('hello') where user='root'; 2.FLUSH PRIVILEGES
忘記root密碼
1.啟動參數增加 --skip-grant-tables備份數據庫
1./usr/local/mysql/bin/mysqldump -u -p napoli > dump.sql
恢復數據庫
1.source dump.sql
創建用戶?
1.CREATE USER xxxx IDENTIFIED BY 'hello'; 2.grant all privileges on napoli.* to 'napoli'@'%' identified by 'napoli' ; #一定要設置兩條記錄,一條%,一條localhost 3.grant all privileges on napoli.* to 'napoli'@'localhost' identified by 'napoli' ; 4.FLUSH PRIVILEGES ;
指定運行目錄
1.vi my.cnf 2. 3.[client] 4.#password = your_password 5.port = 3306 6.socket = /home/mysql/var/mysql.sock 7. 8.# Here follows entries for some specific programs 9. 10.# The MySQL server 11.[mysqld] 12.lower_case_table_names = 1 13.port = 3306 14.socket = /home/mysql/var/mysql.sock 15.basedir = /usr/local/mysql #mysql軟件安裝目錄 16.datadir = /home/mysql/data #mysql數據文件 17.tmpdir = /home/mysql/tmp<span style="white-space: normal;"> </span>
mysql開啟innodb storage engine支持
相關文章:
?
- http://dev.mysql.com/doc/refman/5.1/en/replacing-builtin-innodb.html??innodb plugin install?
- http://dev.mysql.com/doc/refman/5.1/en/innodb-configuration.html?? innodb config
- http://dev.mysql.com/doc/refman/5.1/en/storage-engines.html?? ?storage engines
配置:? $vi /etc/my.cnf
1.[mysqld] 2....... 3.ignore-builtin-innodb 4.plugin-load=innodb=ha_innodb_plugin.so 5. ;innodb_trx=ha_innodb_plugin.so 6. ;innodb_locks=ha_innodb_plugin.so 7. ;innodb_lock_waits=ha_innodb_plugin.so 8. ;innodb_cmp=ha_innodb_plugin.so 9. ;innodb_cmp_reset=ha_innodb_plugin.so 10. ;innodb_cmpmem=ha_innodb_plugin.so 11. ;innodb_cmpmem_reset=ha_innodb_plugin.so 12.innodb_data_home_dir = /usr/local/mysql/var/ 13.innodb_data_file_path = ibdata1:10M:autoextend 14.innodb_log_group_home_dir = /usr/local/mysql/var/ 15.# You can set .._buffer_pool_size up to 50 - 80 % 16.# of RAM but beware of setting memory usage too high 17.innodb_buffer_pool_size = 16M 18.innodb_additional_mem_pool_size = 2M 19.# Set .._log_file_size to 25 % of buffer pool size 20.innodb_log_file_size = 5M 21.innodb_log_buffer_size = 8M 22.innodb_flush_log_at_trx_commit = 1 23.innodb_lock_wait_timeout = 50
查看
1.-bash-3.2# mysql -uroot -p 2.Enter password: 3.Welcome to the MySQL monitor. Commands end with ; or \g. 4.Your MySQL connection id is 232 5.Server version: 5.1.39-log Source distribution 6. 7.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 8. 9.mysql> show plugins; 10.+------------+--------+----------------+---------------------+---------+ 11.| Name | Status | Type | Library | License | 12.+------------+--------+----------------+---------------------+---------+ 13.| binlog | ACTIVE | STORAGE ENGINE | NULL | GPL | 14.| CSV | ACTIVE | STORAGE ENGINE | NULL | GPL | 15.| MEMORY | ACTIVE | STORAGE ENGINE | NULL | GPL | 16.| MyISAM | ACTIVE | STORAGE ENGINE | NULL | GPL | 17.| MRG_MYISAM | ACTIVE | STORAGE ENGINE | NULL | GPL | 18.| InnoDB | ACTIVE | STORAGE ENGINE | ha_innodb_plugin.so | GPL | 19.+------------+--------+----------------+---------------------+---------+ 20.6 rows in set (0.00 sec) 21. 22.mysql> show engines; 23.+------------+---------+------------------------------------------------------------+--------------+------+------------+ 24.| Engine | Support | Comment | Transactions | XA | Savepoints | 25.+------------+---------+------------------------------------------------------------+--------------+------+------------+ 26.| CSV | YES | CSV storage engine | NO | NO | NO | 27.| InnoDB | YES | Supports transactions, row-level locking, and foreign keys | YES | YES | YES | 28.| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO | 29.| MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance | NO | NO | NO | 30.| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO | 31.+------------+---------+------------------------------------------------------------+--------------+------+------------+ 32.5 rows in set (0.00 sec)
Innodb的一些參數,備忘:?
1) =1時,在每個事務提交時,日志緩沖被寫到日志文件,對日志文件做到磁盤操作的刷新。Truly ACID。速度慢。
2) =2時,在每個事務提交時,日志緩沖被寫到文件,但不對日志文件做到磁盤操作的刷新。只有操作系統崩潰或掉電才會刪除最后一秒的事務,不然不會丟失事務。
3) =0時, 日志緩沖每秒一次地被寫到日志文件,并且對日志文件做到磁盤操作的刷新。任何mysqld進程的崩潰會刪除崩潰前最后一秒的事務
1) Default – 使用fsync()。
2) O_SYNC 以sync模式打開文件,通常比較慢。
3) O_DIRECT,在Linux上使用Direct IO。可以顯著提高速度,特別是在RAID系統上。避免額外的數據復制和double buffering(mysql buffering 和OS buffering)。
1) 最少設置為(num_disks+num_cpus)*2。
2) 可以通過設置成1000來禁止這個限制
mysql slow查詢配置?
1.long_query_time=1 2.log-slow-queries=/usr/local/mysql/var/slow.log 3.log-queries-not-using-indexes
?說明:
- long_query_time設置對應slow query的閥值,默認為10
- log-show-queries指定對應的日志輸出路徑
- log-queries-not-using-indexes指定答應沒有走到索引的慢查詢
文檔:?
- http://dev.mysql.com/doc/refman/5.1/en/slow-query-log.html?? 參數配置
- http://dev.mysql.com/doc/refman/5.0/en/mysqldumpslow.html??分析工具
?
分析工具:?http://www.iteye.com/topic/242516
?
總結
以上是生活随笔為你收集整理的mysql一些操作个人备忘(持续更新)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MYSQL小常识
- 下一篇: Replica small data t