转自 :http://www.cnblogs.com/zyqduron/archive/2009/02/12/1389259.html
安装环境
本次安装MySQL的操作系统选用CentOS5.2,mysql选择5.1.31版本。由于现在的mysql被
sun收购,下载免费版本的mysql需要注册,很麻烦,直接到http://linux.softpedia.com/
搜索最新的稳定版本下载即可。
wget ftp://mirror.switch.ch/mirror/mysql/Downloads/MySQL-5.1/mysql-5.1.31.tar.gz
解压 # tar -xvzf msyql-5.1.31.tar.gz
编译安装
# ./configure --prefix=/usr/local/mysql --with-plugins=partition,innobase,myisam,ndbcluster --with-extra-charsets=complex --with-charset=utf8
# make && make install
将mysql的lib文件加载到系统变量中
# vi /etc/ld.so.conf
/usr/local/mysql/lib/mysql
# ldconfig -v | grep mysql
/usr/local/mysql/lib/mysql:
libmysqlclient.so.16 -> libmysqlclient.so.16.0.0
libmysqlclient_r.so.16 -> libmysqlclient_r.so.16.0.0
显示上面信息代表系统加载mysql的lib库正常
创建mysql用户
# useradd -s /sbin/nologin -c 'mysql user' mysql
将安装目录权限修改为mysql
# chown -R mysql.mysql /usr/local/mysql
将对应的配置文件复制到/etc/目录下
# cd /usr/local/mysql/share/mysql
# cp my-large.cnf /etc/my.cnf
编辑my.cnf文件,配置相关参数,结果如下所示:
[client]
port = 3306
socket = /home/mysql/mysql.sock
[mysqld]
port = 3306
socket = /home/mysql/mysql.sock
datadir = /home/mysql # 数据库存放目录
skip-locking
key_buffer = 256M
max_allowed_packet = 1M
table_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
thread_concurrency = 8
log-bin=/home/mysql/mysql-bin # 二进制日志文件的绝对路径
binlog-do-db=gamedb # 需要记录二进制日志的数据库
binlog_format=mixed
log-error=/home/mysql/error.log
pid-file=/home/mysql/mysql.pid
server-id = 10
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[isamchk]
key_buffer = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
生成默认数据库
# /usr/local/mysql/bin/mysql_install_db
将默认数据库的权限修改为mysql
# cd /home/
# chown -R mysql.mysql mysql
安装完毕收尾工作
# cd /usr/local/bin
# ln -s /usr/local/mysql/bin/* .
# cd /usr/local/libexec
# ln -s /usr/local/mysql/libexec/* .
# cd /usr/share/man/man1
# ln -s /usr/local/mysql/share/man/man1/* .
# cd ../man8
# ln -s /usr/local/mysql/share/man/man8/* .
将mysql作为系统服务随系统启动
# cd /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
启动mysql
# mysqld_safe &
或
# service mysqld start
如果报错,查看/home/mysql/error.log文件排查问题
查看数据目录下的文件
ll /home/mysql
-rw-rw---- 1 mysql root 2041 Feb 12 16:57 error.log
-rw-rw---- 1 mysql mysql 10485760 Feb 12 16:56 ibdata1
-rw-rw---- 1 mysql mysql 5242880 Feb 12 16:57 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 Feb 12 15:29 ib_logfile1
drwx------ 2 mysql mysql 4096 Feb 12 15:27 mysql
-rw-rw---- 1 mysql mysql 18902 Feb 12 15:27 mysql-bin.000001
-rw-rw---- 1 mysql mysql 704189 Feb 12 15:27 mysql-bin.000002
-rw-rw---- 1 mysql mysql 125 Feb 12 15:33 mysql-bin.000003
-rw-rw---- 1 mysql mysql 125 Feb 12 16:49 mysql-bin.000004
-rw-rw---- 1 mysql mysql 125 Feb 12 16:56 mysql-bin.000005
-rw-rw---- 1 mysql mysql 125 Feb 12 16:56 mysql-bin.000006
-rw-rw---- 1 mysql mysql 106 Feb 12 16:57 mysql-bin.000007
-rw-rw---- 1 mysql mysql 203 Feb 12 16:57 mysql-bin.index
-rw-rw---- 1 mysql mysql 6 Feb 12 16:57 mysql.pid
srwxrwxrwx 1 mysql mysql 0 Feb 12 16:57 mysql.sock
drwx------ 2 mysql mysql 4096 Feb 12 15:27 test
安装环境
本次安装MySQL的操作系统选用CentOS5.2,mysql选择5.1.31版本。由于现在的mysql被
sun收购,下载免费版本的mysql需要注册,很麻烦,直接到http://linux.softpedia.com/
搜索最新的稳定版本下载即可。
wget ftp://mirror.switch.ch/mirror/mysql/Downloads/MySQL-5.1/mysql-5.1.31.tar.gz
解压 # tar -xvzf msyql-5.1.31.tar.gz
编译安装
# ./configure --prefix=/usr/local/mysql --with-plugins=partition,innobase,myisam,ndbcluster --with-extra-charsets=complex --with-charset=utf8
# make && make install
将mysql的lib文件加载到系统变量中
# vi /etc/ld.so.conf
/usr/local/mysql/lib/mysql
# ldconfig -v | grep mysql
/usr/local/mysql/lib/mysql:
libmysqlclient.so.16 -> libmysqlclient.so.16.0.0
libmysqlclient_r.so.16 -> libmysqlclient_r.so.16.0.0
显示上面信息代表系统加载mysql的lib库正常
创建mysql用户
# useradd -s /sbin/nologin -c 'mysql user' mysql
将安装目录权限修改为mysql
# chown -R mysql.mysql /usr/local/mysql
将对应的配置文件复制到/etc/目录下
# cd /usr/local/mysql/share/mysql
# cp my-large.cnf /etc/my.cnf
编辑my.cnf文件,配置相关参数,结果如下所示:
[client]
port = 3306
socket = /home/mysql/mysql.sock
[mysqld]
port = 3306
socket = /home/mysql/mysql.sock
datadir = /home/mysql # 数据库存放目录
skip-locking
key_buffer = 256M
max_allowed_packet = 1M
table_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
thread_concurrency = 8
log-bin=/home/mysql/mysql-bin # 二进制日志文件的绝对路径
binlog-do-db=gamedb # 需要记录二进制日志的数据库
binlog_format=mixed
log-error=/home/mysql/error.log
pid-file=/home/mysql/mysql.pid
server-id = 10
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[isamchk]
key_buffer = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
生成默认数据库
# /usr/local/mysql/bin/mysql_install_db
将默认数据库的权限修改为mysql
# cd /home/
# chown -R mysql.mysql mysql
安装完毕收尾工作
# cd /usr/local/bin
# ln -s /usr/local/mysql/bin/* .
# cd /usr/local/libexec
# ln -s /usr/local/mysql/libexec/* .
# cd /usr/share/man/man1
# ln -s /usr/local/mysql/share/man/man1/* .
# cd ../man8
# ln -s /usr/local/mysql/share/man/man8/* .
将mysql作为系统服务随系统启动
# cd /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
启动mysql
# mysqld_safe &
或
# service mysqld start
如果报错,查看/home/mysql/error.log文件排查问题
查看数据目录下的文件
ll /home/mysql
-rw-rw---- 1 mysql root 2041 Feb 12 16:57 error.log
-rw-rw---- 1 mysql mysql 10485760 Feb 12 16:56 ibdata1
-rw-rw---- 1 mysql mysql 5242880 Feb 12 16:57 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 Feb 12 15:29 ib_logfile1
drwx------ 2 mysql mysql 4096 Feb 12 15:27 mysql
-rw-rw---- 1 mysql mysql 18902 Feb 12 15:27 mysql-bin.000001
-rw-rw---- 1 mysql mysql 704189 Feb 12 15:27 mysql-bin.000002
-rw-rw---- 1 mysql mysql 125 Feb 12 15:33 mysql-bin.000003
-rw-rw---- 1 mysql mysql 125 Feb 12 16:49 mysql-bin.000004
-rw-rw---- 1 mysql mysql 125 Feb 12 16:56 mysql-bin.000005
-rw-rw---- 1 mysql mysql 125 Feb 12 16:56 mysql-bin.000006
-rw-rw---- 1 mysql mysql 106 Feb 12 16:57 mysql-bin.000007
-rw-rw---- 1 mysql mysql 203 Feb 12 16:57 mysql-bin.index
-rw-rw---- 1 mysql mysql 6 Feb 12 16:57 mysql.pid
srwxrwxrwx 1 mysql mysql 0 Feb 12 16:57 mysql.sock
drwx------ 2 mysql mysql 4096 Feb 12 15:27 test