Table of Contents
不同设备间的mysql共享
nginx+php+phpMyadmin管理mysql
用phpmyadmin管理其他主机的数据库
mysql的主从复制
将server2中的mysql共享至server3,并在server3启动mysql
server2:
[root@server2 local]# rsync -a mysql server3:/usr/local/
root@server3's password:
[root@server2 mysql]# scp /etc/my.cnf server3:/etc/
root@server3's password:
my.cnf 100% 181 166.8KB/s 00:00
server3:
[root@server3 mysql]# groupadd -g 1001 mysql
[root@server3 mysql]# useradd -u 1001 -g 1001 -M -d /usr/local/mysql/ -s /sbin/nologin mysql
[root@server3 mysql]# mkdir -p /data/mysql
[root@server3 mysql]# chown mysql.mysql /data/mysql/
[root@server3 mysql]# vim ~/.bash_profile
[root@server3 mysql]# source ~/.bash_profile
/usr/local/mysql/bin/mysqld
[root@server3 mysql]# mysqld --initialize --user=mysql
2020-08-16T06:03:02.304051Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.21) initializing of server in progress as process 13713
2020-08-16T06:03:02.320821Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-08-16T06:03:03.635711Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-08-16T06:03:05.111290Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ?sF2fqh9u2ku
[root@server3 mysql]# cd support-files/
[root@server3 support-files]# cp mysql.server /etc/init.d/mysqld
[root@server3 support-files]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/server3.err'.
. SUCCESS!
[root@server3 support-files]# mysql -p?sF2fqh9u2ku
mysql> alter user root@localhost identified by 'Zxn@@0823';
mysql> ^DBye
[root@server3 support-files]# mysql -pZxn@@0823
server2:
unzip phpMyAdmin-5.0.2-all-languages.zip
mv phpMyAdmin-5.0.2-all-languages /usr/local/nginx/html/phpmyadmin
cd /usr/local/php/lib/
vim php.ini
systemctl start php-fpm
cd /usr/local/nginx/conf/
vim nginx.conf
systemctl start nginx
访问172.25.11.2/mysqladmin
登陆后可通过phpmyadmin管理数据库
server2:
[root@server2 phpmyadmin]# cp config.sample.inc.php config.inc.php
[root@server2 phpmyadmin]# vim config.inc.php
server3:
mysql -pZxn@@0823
mysql> create user root@'172.25.11.%' identified by 'Zxn@@0823';
mysql> grant all on *.* to root@'172.25.11.%';
mysql> flush privileges;
mysql> create user zxn@'172.25.11.%' identified by 'Zxn@@0823';
mysql> create database westos;
mysql> grant all on westos.* to zxn@'172.25.11.%';
在phpadmin中创建表user_tb
定义表中的数据类型
添加数据 王八蛋 与666
在mysql中查看创建的表
mysql> use westos;
mysql> select * from user_tb;
+-----------+----------+
| nanme | password |
+-----------+----------+
| 王八蛋 | 666 |
| 王八蛋 | 666 |
+-----------+----------+
2 rows in set (0.00 sec)
master设置(server2):
[root@server2 mysql]# vim /etc/my.cnf
[root@server2 mysql]# /etc/init.d/mysqld restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!
[root@server2 mysql]# mysql -pZxn@@0823
mysql> create user 'repl'@'172.25.11.%' identified by 'Zxn@@0823'; 创建复制用户
mysql> grant replication slave on *.* to 'repl'@'172.25.11.%'; 授予用户权限
mysql> flush privileges;
slave(server3)设置:
mysql -h 172.25.11.2 -u repl -pZxn@@0823 检测复制用户是否创建成功
vim /etc/my.cnf
/etc/init.d/mysqld restart
此时切回server2:
查看matser状态
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 1200 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
server3:
配置slave:
mysql -pZxn@@0823
mysql> change master to
-> master_host='172.25.11.2',
-> master_user='repl',
-> master_password='Zxn@@0823',
-> master_log_file='mysql-bin.000001',
-> master_log_pos=1200,
-> get_master_public_key=1;
Query OK, 0 rows affected, 2 warnings (0.02 sec)
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status\G;
#以下两行信息若都显示yes,则证明主从复制成功
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
测试主从复制:
在server2中创建一个表
切到server3发现2中新建的表3也可以看到,主从复制成功