编译安装mysql
#tar zxf mysql-5.1.73.tar.gz
#cd mysql-5.1.73
./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 \
--with-plugins=partition,innobase \
--with-plugin-PLUGIN \
--with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static (参数的作用可到官网查看,本小白也不懂..)
(附官网地址http://dev.mysql.com/doc/refman/5.1/en/source-configuration-options.html)
#make && make install
2创建mysqld_multi的配置文件 (只有几条必要参数)
#vim /usr/local/mysql/conf/my.cnf (配置文件可以在其他位置,启动数据库的时候指定即可)
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user = root (MySQL的用户,可以不加)
password = 111111 (可以不加此参数,若加,需要在启动数据库之后修改相应用户的密码 才能关闭数据库)
[mysqld3306]
socket = /data/3306/3306.sock
port = 3306
pid-file = /data/3306/3306.pid
datadir = /data/3306/data/
log = /data/3306/3306.log
[mysqld3307]
socket = /data/3307/3307.sock
port = 3307
pid-file = /data/3307/3307.pid
datadir = /data/3307/data/
log = /data/3307/3307.log
3创建多实例
#mkdir -p /data/{3306,3307}/data
#chown -R mysql.mysql /data
/usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/3306/data/ --user=mysql (初始化实例3306)
/usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/3307/data/ --user=mysql(初始化实例3307)
(若不指定basedir,可能会报错)
4启动实例
/usr/local/mysql/bin/mysqld_multi --defaults-extra-file=/usr/local/mysql/conf/my.cnf start 3306 (启动实例3306)
/usr/local/mysql/bin/mysqld_multi --defaults-extra-file=/usr/local/mysql/conf/my.cnf start 3307 (启动实例3307)
/usr/local/mysql/bin/mysqld_multi --defaults-extra-file=/usr/local/mysql/conf/my.cnf start 3306-3307 (同时启动)
5修改mysql的root用户的密码
mysql -uroot password 123456 -S /data/3306/3306.sock (无密码,直接设置密码为123456)
mysql -uroot -p123456 -S /data/3306/3306.sock (修改密码,123456为新密码,输入回车后会提示输入原密码)
6停止实例
与启动实例命令相同,把start换成stop
本文出自 “little_monkey” 博客,谢绝转载!