== mysql 一机多主实践 ==

分类:技术文档 - JS文档 | 阅读(3265) | 发布于:2014-03-07 09:05

== mysql 一机多主实践 ==
   安装mysql 采用yum的方式
  * [[http://192.168.1.201:8080/trac/wiki/yum%E9%85%8D%E7%BD%AE|yum 配置]]
== linux 基础操作 ==
  * 添加一个multi用户,并加入到mysql组
  
{{{
 useradd multi -g mysql -s /sbin/nologin
}}}
  * 给multi用户添加密码,这里设置的密码为multi

{{{
  passwd multi
}}}
 

== 安装mysql ==
  
{{{
 yum install mysql-server
}}}

== mysql配置文件 ==


{{{
[client]
default-character-set = utf8

[mysqld_multi]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
user = multi
password = multi
log = /opt/mysql/multi.log

[mysqld3306]
user = mysql
port = 3306
socket = /opt/mysql/3306/mysql.sock
pid-file = /opt/mysql/3306/mysql.pid
datadir = /opt/mysql/3306
server-id = 1

[mysqld3307]
user = mysql
port = 3307
socket = /opt/mysql/3307/mysql.sock
pid-file = /opt/mysql/3307/mysql.pid
datadir = /opt/mysql/3307
server-id = 2

[mysqld3308]
user = mysql
port = 3308
socket = /opt/mysql/3308/mysql.sock
pid-file = /opt/mysql/3308/mysql.pid
datadir = /opt/mysql/3308
server-id = 3

[mysqld3309]
user = mysql
port = 3309
socket = /opt/mysql/3309/mysql.sock
pid-file = /opt/mysql/3309/mysql.pid
datadir = /opt/mysql/3309
server-id = 4
}}}

== 初始化操作 ==

1. 初始化mysql数据库
{{{
mysql_install_db --user=mysql --datadir=/opt/mysql/3306 --default-storage-engine=Innodb
}}}

2. 启动mysql

{{{
 mysqld_multi start 3306
}}}

3. 修改密码

{{{
 mysqladmin -u root -S /opt/mysql/3306/mysql.sock password miaohr1qaz
}}}

4. 登录数据库

{{{
 mysql -u root -pmiaohr1qaz -S /opt/mysql/3306/mysql.sock
}}}
5. 给multi用户添加权限

{{{
 mysql> GRANT SHUTDOWN ON *.* TO 'multi'@'localhost' IDENTIFIED BY 'multi';
}}}

6. 设置root 远程访问


{{{
mysql> UPDATE mysql.user SET Host='%' WHERE Host='localhost' ;

mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%";

mysql> FLUSH PRIVILEGES ;
}}}


7. 可能会遇到的问题
{{{
配 置mysql文件(my.cnf)完成并初始化成功后,在登录时出现“ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/mysql/3306/mysql.sock' (2)”的错误,一般出现这样的问题就要
1.先查看登录的sock路径写的是否正确,其次是配置文件中socket路径是否正确
2.查看文件内的*.err的错误日志,对照上面显示的【error】错误原因进行更改
3.查看进程,是否端口被占用,如果是,则杀死进程

然后再次初始化并启动mysql服务即可
}}}

 


标签: