/usr/local/mysql/bin/mysql_install_db --user=mysql --datadir=/home/mysql/var ##指定安装后的数据目录
mysql 启动/关闭
/usr/local/mysql/bin/mysqld_safe --defaults-file=/home/mysql/.my.cnf --user=mysql & #启动 /usr/local/mysql/bin/mysqladmin --defaults-file=/home/mysql/.my.cnf shutdown -uroot -p #关闭
update user set password=password('hello') where user='root'; FLUSH PRIVILEGES ;
启动参数增加 --skip-grant-tables
备份数据库
/usr/local/mysql/bin/mysqldump -u -p napoli > dump.sql
恢复数据库
source dump.sql
创建用户
CREATE USER xxxx IDENTIFIED BY 'hello'; grant all privileges on napoli.* to 'napoli'@'%' identified by 'napoli' ; #一定要设置两条记录,一条%,一条localhost grant all privileges on napoli.* to 'napoli'@'localhost' identified by 'napoli' ; FLUSH PRIVILEGES ;
指定运行目录
vi my.cnf
[client]
#password = your_password
port = 3306
socket = /home/mysql/var/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
lower_case_table_names = 1
port = 3306
socket = /home/mysql/var/mysql.sock
basedir = /usr/local/mysql #mysql软件安装目录
datadir = /home/mysql/data #mysql数据文件
tmpdir = /home/mysql/tmp
相关文章:
[mysqld] ...... ignore-builtin-innodb plugin-load=innodb=ha_innodb_plugin.so ;innodb_trx=ha_innodb_plugin.so ;innodb_locks=ha_innodb_plugin.so ;innodb_lock_waits=ha_innodb_plugin.so ;innodb_cmp=ha_innodb_plugin.so ;innodb_cmp_reset=ha_innodb_plugin.so ;innodb_cmpmem=ha_innodb_plugin.so ;innodb_cmpmem_reset=ha_innodb_plugin.so innodb_data_home_dir = /usr/local/mysql/var/ innodb_data_file_path = ibdata1:10M:autoextend innodb_log_group_home_dir = /usr/local/mysql/var/ # You can set .._buffer_pool_size up to 50 - 80 % # of RAM but beware of setting memory usage too high innodb_buffer_pool_size = 16M innodb_additional_mem_pool_size = 2M # Set .._log_file_size to 25 % of buffer pool size innodb_log_file_size = 5M innodb_log_buffer_size = 8M innodb_flush_log_at_trx_commit = 1 innodb_lock_wait_timeout = 50
-bash-3.2# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 232 Server version: 5.1.39-log Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show plugins; +------------+--------+----------------+---------------------+---------+ | Name | Status | Type | Library | License | +------------+--------+----------------+---------------------+---------+ | binlog | ACTIVE | STORAGE ENGINE | NULL | GPL | | CSV | ACTIVE | STORAGE ENGINE | NULL | GPL | | MEMORY | ACTIVE | STORAGE ENGINE | NULL | GPL | | MyISAM | ACTIVE | STORAGE ENGINE | NULL | GPL | | MRG_MYISAM | ACTIVE | STORAGE ENGINE | NULL | GPL | | InnoDB | ACTIVE | STORAGE ENGINE | ha_innodb_plugin.so | GPL | +------------+--------+----------------+---------------------+---------+ 6 rows in set (0.00 sec) mysql> show engines; +------------+---------+------------------------------------------------------------+--------------+------+------------+ | Engine | Support | Comment | Transactions | XA | Savepoints | +------------+---------+------------------------------------------------------------+--------------+------+------------+ | CSV | YES | CSV storage engine | NO | NO | NO | | InnoDB | YES | Supports transactions, row-level locking, and foreign keys | YES | YES | YES | | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO | | MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance | NO | NO | NO | | MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO | +------------+---------+------------------------------------------------------------+--------------+------+------------+ 5 rows in set (0.00 sec)
mysql slow查询配置
long_query_time=1 log-slow-queries=/usr/local/mysql/var/slow.log log-queries-not-using-indexes
说明:
文档:
分析工具: http://www.iteye.com/topic/242516
----------------------------------------- 分割线(2011-07-14日更新)---------------------------------------
mysql 索引机制
文章: http://www.cnblogs.com/leoo2sk/archive/2011/07/10/mysql-index.html
mysql 优化分析
查询索引:
show index from table;
分析执行计划:
explain select * from user where user_id = '10' and user_name = 'Xiongchang.liuxch'; +----+-------------+-------+-------+-------------------+---------+---------+-------+------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+-------+-------------------+---------+---------+-------+------+-------+ | 1 | SIMPLE | user | const | PRIMARY,user_name | PRIMARY | 4 | const | 1 | | +----+-------------+-------+-------+-------------------+---------+---------+-------+------+-------+
set profiling =1;
show profiles; +----------+------------+-------------------------------------------------------------------------------------+ | Query_ID | Duration | Query | +----------+------------+-------------------------------------------------------------------------------------+ | 1 | 0.00065700 | select * from user | | 2 | 0.00035900 | show index from user | | 3 | 0.00009200 | select * from user_id = '10' |