mysql基础功能----phpmyadmin数据库管理工具,远程连接数据库,对用户授予制定权限,主从同步

一.添加数据库管理工具phpmyadmin

[root@foundation13 ~]# scp phpMyAdmin-5.0.2-all-languages.zip server1:/usr/local/lnmp/nginx/html/phpadmin
root@server1's password: 
phpMyAdmin-5.0.2-all-languages.zip                                                                                  100%   14MB 195.1MB/s   00:00   
[root@server1 html]# ls
50x.html  bbs  download  example.php  index.html  index.php  memcache.php  phpadmin  redhat.jpg
[root@server1 html]# unzip phpadmin
[root@server1 html]# ls
50x.html  bbs  download  example.php  index.html  index.php  memcache.php  phpadmin  phpMyAdmin-5.0.2-all-languages  redhat.jpg
[root@server1 html]# rm -fr phpadmin
[root@server1 html]# mv phpMyAdmin-5.0.2-all-languages phpadmin
[root@server1 html]# ls
50x.html  bbs  download  example.php  index.html  index.php  memcache.php  phpadmin  redhat.jpg
[root@server1 html]# mv phpadmin phpmyadmin
[root@server1 html]# cd ..
[root@server1 nginx]# cd conf
[root@server1 conf]# vim nginx.conf
[root@server1 conf]# nginx -t 
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server1 conf]# nginx -s reload
[root@server1 conf]# cd ..
[root@server1 nginx]# cd html
[root@server1 html]# ls
50x.html  bbs  download  example.php  index.html  index.php  memcache.php  phpmyadmin  redhat.jpg
[root@server1 html]# cd /usr/local/lnmp/php
[root@server1 php]# ls
bin  etc  include  lib  php  sbin  var
[root@server1 php]# cd lib
[root@server1 lib]# vim php.ini
[root@server1 lib]# systemctl reload php-fpm

php.ini
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

二.远程连接

设置远程主机可以连接
[root@server1 phpmyadmin]# pwd
/usr/local/lnmp/nginx/html/phpmyadmin
[root@server1 phpmyadmin]# vim config.inc.php
[root@server1 phpmyadmin]# nginx -s reload

在这里插入图片描述
创建root用户,授予对172.25.13网段数据库的全部权限

[root@server3 local]# mysql -pWestos_007
mysql> create user root@'172.25.13.%' identified by 'Westos_007';
Query OK, 0 rows affected (0.02 sec)

mysql> grant all on *.* to root@'172.25.13.%';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
[root@server3 local]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL.. SUCCESS! 

在这里插入图片描述

三.建立用户,授予指定数据库权限

[root@server3 local]# mysql -pWestos_007
mysql> create user lj@'172.25.13.%' identified by 'Westos_007';
Query OK, 0 rows affected (0.02 sec)

mysql> create database westos;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on westos.* to lj@'172.25.13.%';       //只能对westos数据库进行操作
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye
[root@server3 local]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL.. SUCCESS! 

在这里插入图片描述
在指定数据库westos中新建表
在这里插入图片描述
表中插入数据
在这里插入图片描述

三.主从同步

1.server中创建用户repl,授予复制文件权限,

[[root@server1 lib]# vim /etc/my.cnf
[root@server1 lib]# cd /usr/local/lnmp/nginx/html/phpmyadmin
[root@server1 phpmyadmin]# mysql -pWestos_007
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.21 Source distribution

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create user 'repl'@'172.25.13.%' identified by 'Westos_007';
Query OK, 0 rows affected (0.01 sec)

mysql> grant replication slave on *.* to 'repl'@'172.25.13.%';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye

2.设置server3的id为2(从机),重启数据库

/etc/my.cnf

[root@server1 lib]# vim /etc/my.cnf
[root@server1 phpmyadmin]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 

在这里插入图片描述

3.server3中设置复制文件的原主机,用户,复制的日志文件,密码之后刷新数据库

[root@server3 local]# vim /etc/my.cnf
[root@server3 local]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL.. SUCCESS! 
[root@server3 local]# mysql -h 172.25.13.1 -urepl -pWestos_007
mysql> show database;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)

[root@server3 local]# mysql -pWestos_007
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 116
Server version: 8.0.21 Source distribution

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CHANGE MASTER TO
    -> MASTER_HOST='172.25.13.1',
    -> MASTER_USER='repl',
    -> MASTER_PASSWORD='Westos_007',
    -> MASTER_LOG_FILE='mysql-bin.000001',
    -> MASTER_LOG_POS=156,
    -> GET_MASTER_PUBLIC_KEY=1;
Query OK, 0 rows affected, 2 warnings (0.05 sec)

mysql> START SLAVE;
Query OK, 0 rows affected (0.01 sec)

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.25.13.1
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 156
               Relay_Log_File: server3-relay-bin.000003
                Relay_Log_Pos: 509
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 

4.编辑/etc/my.cnf,设置server1为主机,重启数据库

在这里插入图片描述

5.主机中新建数据库,从机可以访问到,日志文件更改

server1:
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 |      156 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> CREATE DATABASE test;
Query OK, 1 row affected (0.01 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test               |
+--------------------+
5 rows in set (0.01 sec)


mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 |      341 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> exit

server3:
mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.25.13.1
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 341
               Relay_Log_File: server3-relay-bin.000003
                Relay_Log_Pos: 509
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test               |
| westos             |
+--------------------+
6 rows in set (0.01 sec)

mysql> exit

6.主机进行插入操作,从机可以访问到

test中插入数据
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

server1
[root@server1 phpmyadmin]# mysql -pWestos_007
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 83
Server version: 8.0.21 Source distribution

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000002 |      778 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| client         |
+----------------+
1 row in set (0.00 sec)

mysql> select * from client;
+--------+----------+--------+
| name   | password | city   |
+--------+----------+--------+
| 小海   |  1234566 | 成都   |
| 陈兵   |   333333 | 海南   |
+--------+----------+--------+
2 rows in set (0.00 sec)

server2
[root@server3 local]# mysql -pWestos_007
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 149
Server version: 8.0.21 Source distribution

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| client         |
| user           |
+----------------+
2 rows in set (0.00 sec)

mysql> select client;
ERROR 1054 (42S22): Unknown column 'client' in 'field list'
mysql> select * from client;
+--------+----------+--------+
| name   | password | city   |
+--------+----------+--------+
| 小海   |  1234566 | 成都   |
| 陈兵   |   333333 | 海南   |
+--------+----------+--------+
2 rows in set (0.00 sec)

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.25.13.1
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000002
          Read_Master_Log_Pos: 778
               Relay_Log_File: server3-relay-bin.000005
                Relay_Log_Pos: 993
        Relay_Master_Log_File: mysql-bin.000002
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值