之前电脑里的一些做过的文案做一下分享:
卸载mysql服务相关
yum -y remove mysql*
1. 安装mysql 服务器端:
yum install mysql-server
yum install mysql-devel
2. 安装mysql客户端:
yum install mysql
3. 启动mysql服务:
service mysqld start或者/etc/init.d/mysqld start
停止:
service mysqld stop
重启:
service mysqld restart
4. 创建root管理员:
mysqladmin -u root password 123456
5.登陆
mysql -uroot -p123456
mysql服务器的主从配置,这样可以实现读写分离,也可以在主库挂掉后从备用库中恢复
需要两台机器,安装mysql,两台机器要在相通的局域网内
主机A: 192.168.1.100
从机B:192.168.1.101
可以有多台从机
1、先登录主机 A
mysql>GRANT REPLICATION SLAVE ON *.* TO ‘backup’@’192.168.1.101‘ IDENTIFIED BY ‘123456’;
赋予从机权限,有多台丛机,就执行多次
2、 打开主机A的my.cnf,输入
server-id = 1 #主机标示,整数
log_bin = /var/log/mysql/mysql-bin.log #确保此文件可写
read-only =0 #主机,读写都可以
binlog-do-db =test #需要备份数据,多个写多行
binlog-ignore-db =mysql #不需要备份的数据库,多个写多行
3、打开从机B的my.cnf,输入
server-id = 2
log_bin = /var/log/mysql/mysql-bin.log
master-host =192.168.1.100
master-user =backup
master-pass =123456
master-port =3306
master-connect-retry=60 #如果从服务器发现主服务器断掉,重新连接的时间差(秒)
replicate-do-db =test #只复制某个库
replicate-ignore-db=mysql #不复制某个库
4、同步数据库
不用太费事,只把主从库都启动即可自动同步,如果不嫌麻烦的话可以把主库的内容导出成SQL,然后在从库中运行一遍
5、先重启主机A的mysql,再重启从机B的mysql
6、验证
在主机A中,mysql>show master status\G;
在从机B中,mysql>show slave status\G;
能看到大致这些内容
File: mysql-bin.000001
Position: 1374
Binlog_Do_DB: test
Binlog_Ignore_DB: mysql
可以在主机A中,做一些INSERT, UPDATE, DELETE 操作,看看主机B中,是否已经被修改
GRANT REPLICATION SLAVE,RELOAD,SUPER ON *.* TO mysql_backup@'*' IDENTIFIED BY '123456';
CHANGE MASTER TO master_host = '127.0.0.1',
master_user = 'mysql_backup',
master_password = '123456',
master_log_file = 'mysql-bin.000001',
master_log_pos = 343;
server {
listen 80;
server_name _;
access_log logs/likang.default.access.log main;
error_log logs/error.log error;
root /var/www/html/likang/default;
location / {
index index.html index.htm index.php;
if (!-e $request_filename) {
#rewrite . /index.php last;
}
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/html/likang/default/$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
}