规划
数据库目录
[root@localhost ~]# ll /data/MySQL/
drwxr-xr-x 4 mysql mysql 4096 03-22 17:33 data1
drwxr-xr-x 4 mysql mysql 4096 03-22 17:33 data2
所占用的端口
data1 占用3306端口
data2 占用3307端口
数据库安装
tar -zxvf mysql-5.1.44.tar.gz
cd mysql-5.1.44
./configure --prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile
make && make install
cd ../
mkdir -p /data/mysql
mkdir /data/mysql/data1
mkdir /data/mysql/data2
groupadd mysql
useradd -g mysql mysql
更改mysql用户密码
passwd mysql
创建mysql配置文件my.cnf
cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
编辑MYSQL配置文件my.cnf
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
[mysqld1]
port = 3306
socket = /tmp/mysql3306.sock
pid-file = /data/mysql/data1/mysql3306.pid
datadir = /data/mysql/data1
skip-name-resolve
log-bin = mysql-bin-3306
log_slave_updates
expire_logs_days = 7
log-error = /data/mysql/data1/mysql3306.err
log_slow_queries = mysql3306-slow.log
long_query_time = 3
query_cache_size = 64M
query_cache_limit = 2M
slave-net-timeout = 10
[mysqld2]
port = 3307
socket = /tmp/mysql3307.sock
pid-file = /data/mysql/data2/mysql3307.pid
datadir = /data/mysql/data2
skip-name-resolve
log-bin = mysql-bin-3307
log_slave_updates
expire_logs_days = 7
log-error = /data/mysql/data1/mysql3307.err
log_slow_queries = mysql3307-slow.log
long_query_time = 3
query_cache_size = 64M
query_cache_limit = 2M
slave-net-timeout = 10
安装目录赋予用户组权限
chgrp -R mysql /usr/local/mysql/*
初始化数据库
/usr/local/mysql/bin/mysql_install_db --datadir=/data/mysql/data1 --user=mysql
/usr/local/mysql/bin/mysql_install_db --datadir=/data/mysql/data2 --user=mysql
chown -R mysql:mysql /data/*
启动数据库
/usr/local/mysql/bin/mysqld_multi --config-file=/etc/my.cnf start 1
/usr/local/mysql/bin/mysqld_multi --config-file=/etc/my.cnf start 2
报错信息:
Unmatched right curly bracket at /usr/local/mysql/bin/mysqld_multi line 171, at end of line
syntax error at /usr/local/mysql/bin/mysqld_multi line 171, near "}"
Execution of /usr/local/mysql/bin/mysqld_multi aborted due to compilation errors
由于mysql5.1.44存在BUG所以需要删除文件/usr/local/mysql/bin/mysqld_multi中的74行多余的“}”;
删除后无报错信息
还有可能出现如下报错信息:
WARNING: my_print_defaults command not found.
Please make sure you have this command available and
in your path. The command is available from the latest
MySQL distribution.
WARNING: --config-file is deprecated and will be removed
in MySQL 5.6. Please use --defaults-extra-file instead
ABORT: Can't find command 'my_print_defaults'.
This command is available from the latest MySQL
distribution. Please make sure you have the command
in your PATH.
原因:由于你安装的mysql bin 路径不在默认的搜索path中,导致在启动时无法正确的传送参数给/usr/local/mysql/libexec/mysqld
解决方法:
echo "PATH=/usr/local/mysql/bin:\$PATH" >> /etc/profile
重启系统使系统变量生效
查看端口
netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 31964/mysqld
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 32034/mysqld
###可以看到3306 3307已经启动
修改密码
/usr/local/mysql/bin/mysqladmin -uroot password "123456" -S /tmp/mysql3307.sock
/usr/local/mysql/bin/mysqladmin -uroot password "123456" -S /tmp/mysql3306.sock
登录数据库
mysql -uroot -p -S /tmp/mysql3307.sock
