随笔-159  评论-114  文章-7  trackbacks-0
安装MySQL之前,先检查是否已经有没用的旧有MySQL

不卸载,有乱七八糟的问题会出现

rpm -qa|grep mysql -i

发现老版本的,就卸载

rpm ---nodeps --allmatches mysql-4.1.22-2.e14

下面开始安装,强制安装丫的

rpm -ivh MysqlServer.rpm --nodeps --force

安装顺序  server dev share client debuginfo

netstat -nat

察看是否启动。

配置/etc/my.cnf

# The following options will be passed to all MySQL clients
[client]
#password       
= your_password
port            
= 3306
socket          
= /data/mysql/database/mysql.sock

# Here follows entries 
for some specific programs

# The MySQL server
[mysqld]
port            
= 3306
socket          
= /data/mysql/database/mysql.sock
datadir         
= /data/mysql/database/
pid
-file        = /data/mysql/database/mysql.pid

skip
-locking
key_buffer_size 
= 2048M
max_allowed_packet 
= 2M
table_open_cache 
= 512
sort_buffer_size 
= 8M
read_rnd_buffer_size 
= 4M

query_cache_size 
= 1M
query_cache_type 
= 1

# Try number of CPU
's*2 for thread_concurrency
thread_concurrency = 16
thread_cache_size 
= 8
innodb_file_per_table

read_buffer_size 
= 4M
myisam_sort_buffer_size 
= 4M
myisam_recover
myisam_repair_threads
=4

server
-id = 1
log
-bin=/data/mysql_backup/binlogs/database
max_binlog_size 
= 512M
expire_logs_days 
= 3
long_query_time 
= 2 
log
-slow-queries = slow.log 
log
-queries-not-using-indexes
event_scheduler
=1
# Uncomment the following 
if you are using InnoDB tables
innodb_data_home_dir 
= /data/mysql/database/
innodb_data_file_path 
= ibdata1:20M;ibdata2:10M:autoextend
#innodb_log_group_home_dir 
= /var/lib/mysql/
#innodb_log_arch_dir 
= /var/lib/mysql/
# You can set .._buffer_pool_size up to 
50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size 
= 10000M
innodb_additional_mem_pool_size 
= 4M
# Set .._log_file_size to 
25 % of buffer pool size
innodb_log_file_size 
= 8M
innodb_log_buffer_size 
= 4M
#innodb_flush_log_at_trx_commit 
= 1
#innodb_lock_wait_timeout 
= 50

##
#interactive_timeout
=6048000

wait_timeout
=31536000
interactive_timeout
=31536000
connect_timeout
=60
max_connect_errors
=100000000
max_connections
=50

[mysqldump]
quick
max_allowed_packet 
= 16M

[mysql]
no
-auto-rehash
# Remove the next comment character 
if you are not familiar with SQL
#safe
-updates

[isamchk]
key_buffer_size 
= 256M
sort_buffer_size 
= 256M
read_buffer_size 
= 128M
write_buffer_size 
= 128M

[myisamchk]
key_buffer_size 
= 256M
sort_buffer_size 
= 256M
read_buffer_size 
= 128M
write_buffer_size 
= 128M

[mysqlhotcopy]
interactive
-timeout

service mysql stop

如果目录改变了,那么需要重新建立新数据库目录

那么my.cnf中两个目录的属主需要配置,否则也会有问题

chown -R mysql.mysql /data/mysql

chown 
-R mysql.mysql /data/mysql_backup

mysql_install_db --defaults-file=/etc/my.cnf --user=mysql

输出正常自己察看

看看/data/mysql/下面的database中是否有ib开带头的几个文件,ibdata1 ibdata2  log 等。InnoDB数据实际都放在一个大文件里面

service mysql start

新install_db 的不需要密码,如果mysql -uroot -p
再回车,需要数据密码才能登录,那肯定不对。

检查ps -efww|grep mysql  看看进程使用的my.cnf是否正确。

正常登录后
mysql> show engines;

+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine     | Support | Comment                                                        | Transactions | XA   | Savepoints |
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| InnoDB     | YES     | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| BLACKHOLE  | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| CSV        | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
| FEDERATED  | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
| ARCHIVE    | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance         | NO           | NO   | NO         |
+------------+---------+----------------------------------------------------------------+--------------+------+------------+


无需密码。我们设置一下。

注意MySql 5.1 使用old_password函数设置,java程序才是对,否则程序总是会报Access Denied,其实密码是对的。格式如下

  use mysql; 
  update user set password
=old_password("new_pass") where user="root";修改密码 
  flush privileges; 刷新权限

mysql>GRANT ALL ON *.* TO 'root'@'%' 
mysql
>flush privileges;

设置一下其他地址使用root 登录mysql的远程访问权限

nohup mysql -uroot -ppassword --default-character-set=utf8 < /data/t.sql &

 ps -aux|grep mysql

什么时候Done了,就导完数据。

ll -h /data/mysql/database

mysql -uroot --/data/mysql/database/mysql.sock

有时候,会mysql等不了或者关闭不了,必须找到驱动才能关闭或者登陆

mysqladmin -uroot --/data/mysql/database/mysql.sock shutdown

备份数据dump操作

mysqldump -uroot --/data/mysql/database/mysql.sock --B tianwen tianwen_log -> /data/bak0408.sql

 =================

优化Innodb 的my.cnf

grep innodb /etc/my.cnf

innodb_additional_mem_pool_size = 20M
innodb_buffer_pool_size 
= 12G
innodb_data_file_path 
= ibdata1:4G;ibdata2:50M:autoextend
innodb_file_io_threads 
= 8
innodb_thread_concurrency 
= 16
#innodb_flush_log_at_trx_commit 
= 1
innodb_log_buffer_size 
= 16M
innodb_log_file_size 
= 256M
innodb_log_files_in_group 
= 3
innodb_max_dirty_pages_pct 
= 90
#innodb_lock_wait_timeout 
= 120
innodb_file_per_table
=1
innodb_rollback_on_timeout

max_connections = 1200  也最好设置大点,大规模操作数据会比较顺畅。

posted on 2010-04-10 13:38 北国狼人的BloG 阅读(189) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: