mysql tips 启多个server[端口]

配置一台服务器启多个server,老是记不住,这次记录下来

建立好新数据库的位置,计划启动2个server
/data1/mysql1/data/mysql #mysql1,mysql2是两个数据库的目录,data/mysql 是存放mysql初始数据库的位置
/data1/mysql2/data/mysql

cp -R /usr/local/mysql/var/mysql/* /data1/mysql1/data/mysql/ #将mysql初始数据库copy过来
也可以使用scripts/mysql_install_db初始化数据库

设置目录权限mysql:mysql

修改my.cnf
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user = root
password = 123456

[mysqld1]
port      = 3306
socket    = /tmp/mysql.sock1
pid-file=/data1/mysql1/db-app1.pid
log=/data1/mysql1/db-app.log
datadir = /data1/mysql1/data
user = root

[mysqld2]
port = 3307
socket = /tmp/mysql.sock2
pid-file=/data1/mysql2/db-app1.pid
log=/data1/mysql2/db-app.log
datadir = /data1/mysql2/datauser = mysql
user = root

[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/mysqld_multi –config-file=/etc/my.cnf start 1,2 &

连接测试
mysql -uroot -S /tmp/mysql.sock2

mysql安装:
shell> groupadd mysql

shell> useradd -g mysql mysql

shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -

shell> cd mysql-VERSION

shell> ./configure –prefix=/usr/local/mysql

shell> make

shell> make install

shell> cp support-files/my-medium.cnf /etc/my.cnf

shell> cd /usr/local/mysql

shell> bin/mysql_install_db –user=mysql

shell> chown -R root .

shell> chown -R mysql var

shell> chgrp -R mysql .

shell> bin/mysqld_safe –user=mysql &

/usr/local/mysql/bin/mysqld_safe –defaults-file=/etc/my.cnf

给用户设置初始密码
UPDATE mysql.user SET Password = PASSWORD(’123456′);

FLUSH PRIVILEGES;

DELETE FROM mysql.user WHERE User = ”; 删除匿名帐户

FLUSH PRIVILEGES;

停止mysql
/usr/local/mysql/bin/mysqladmin shutdown

将mysql运行命令写入自启动
vi /etc/rc.local

出现找不到my_print_default是由于没设置环境变量
export PATH=$PATH:/usr/local/mysql/bin/或vi /etc/profile增加即可

觉得文章有用?立即: 和朋友一起 共学习 共进步!

猜想失败,您看看下面的文章有用吗?

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>