1.service mysqld stop
2.拷贝或创建数据文件
cp -r /var/lib/mysql /var/lib/mysql_3307
或者
mkdir /var/lib/mysql_3307
mysql_install_db --datadir=/var/lib/mysql_3307 --usre=mysql
3.chown -R mysql.mysql /var/lib/mysql_3307
4.vi /etc/my_multi.cnf
[mysqld_multi]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
user = root#用于登陆和关闭此服务
password = 123456#同上
[mysqld3307]
socket = /tmp/mysql_3307.sock
port = 3307
pid-file = /var/lib/mysql_3307/3307.pid
datadir = /var/lib/mysql_3307/
log = /var/lib/mysql_3307/3307.log
user = mysql
5.service mysqld restart(启动3306)
mysqld_multi --defaults-extra-file=/usr/local/my_multi.cnf start 3307(启动3307)
netstat -tlunp | grep mysql(看有没有3306,3307两个端口,没有重启电脑,启动3307)
6.此时密码为空,
如果没有密码则,
mysqladmin -u root -S /tmp/mysql_3307.sock password 123456(设置密码为123456)
如果有密码123456想修改密码为111则
mysqladmin -u root -S /tmp/mysql_3307.sock password 111 -p
输入123456就可以了
7.登陆
mysql -u root -S/tmp/mysql_3307.sock -p
输入111就可以了
本文转自神ge 51CTO博客,原文链接:http://blog.51cto.com/12218412/1865772