安裝數據庫有兩種方法。第一種是源碼安裝,第二種是二進制安裝。源碼安裝比較容易。在嘗試二進制安裝後,碰到一些事記錄下來
yum 安裝:
查看yum下可以安裝mysql的版本:
yum list | grep mysql
發現版本是5.1.X版本,可以修改配置,使用yum安裝mysql最新版本。
在安裝過程中,想安裝指定的版本,所以不能使用yum安裝了。
二進制安裝:
1、下載指定版本的二進制文件,下載地址:http://downloads.mysql.com/archives/community/。可以選擇任何版本。我選擇的是5.6.29
2、解壓下載的mysql-5.6.29-linux-glibc2.5-i686.tar.gz文件,複製文件到/usr/local:cp mysql-5.6.29 /usr/local/mysql
3、增加mysql組和用戶:
groupadd mysql
#爲組增加mysql用戶
useradd -r -g mysql -s /bin/false mysql
chown -R mysql /usr/local/mysql
chgrp -R mysql /usr/local/mysql
/usr/local/mysql/scripts/mysql_install_db --user=mysql
4、創建配置文件 my.ini
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
#password = your_password
port = 3306
socket = /data/mysql/database/mysql.sock
# The MySQL server
[mysqld]
port = 3306
socket = /data/mysql/database/mysql.sock
datadir = /data/mysql/database/
pid-file = /data/mysql/database/mysql.pid
basedir =/usr/local/mysql/
server-id = 1
log-bin=/data/mysql_backup/binlogs/database
binlog_format = MIXED
max_binlog_size = 512M
expire_logs_days = 3
long_query_time = 2
slow-query-log-file = slow.log
log-queries-not-using-indexes
event_scheduler=1
wait_timeout=315360000
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
5、使用/usr/local/mysql/bin/mysqld_safe啓動
/usr/local/mysql/bin/mysqld_safe --default-file=my.ini &
6、可以將mysql作爲linux的service
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
cp my.ini /etc/my.ini做全局配置文件
這樣便可以使用service mysql start或者service mysql stop