一.安装准备工作
首先是他的安装 我们选择mariadb这个mysql的一个社区版,功能都是一样的
很简单
[root@hpb ~]# yum install mariadb*
接下是启动
[root@hpb ~]# systemctl start mariadb
#然后可以查看一下服务的状态,如过没有红色报错的话 大抵是成功的
[root@hpb ~]# systemctl status mariadb
#再其次我们应该做的是让他随系统启动时启动
[root@hpb ~]# systemctl enable mariadb
然后我们需要配置一下自己的防火墙 mysql默认监听的是所有接口的 3306端口
查看mysql监听的端口
[root@hpb ~]# ss -tulpn |grep mysql
tcp LISTEN 0 50 *:3306 *:* users:(("mysqld",pid=4683,fd=14))
[root@hpb ~]#
#设置防火墙对mysql放行
[root@hpb ~]# firewall-cmd --permanent --add-service=mysql
success
#让防火墙重新加载
[root@hpb ~]# firewall-cmd --reload
success
准备工作的最后一步就是设置一下他的安全性问题
[root@hpb ~]# mysql_secure_installation #不带参数执行
#每一步都会有提示 密码设置外 其他都回答Y就可以了
二.基本使用
[root@hpb ~]# mysql -u root -h localhost -p123456
#以root身份登录 -h选项参数如果不加上的话默认为localhost登录
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
#查看数据库中的数据库条目
MariaDB [(none)]> CREATE DATABASE mytest;
Query OK, 1 row affected (0.00 sec)
#创建一个数据库 mytest
MariaDB [(none)]> USE mysql;
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
#使用该数据库
MariaDB [mysql]> show tables;
#查看表目录
这时候我们导入一个数据库备份
mysql -u root -p123456 -t < employees.sql
#再查看的话 我们就多出来一个数据库 用它来做练习基本的增删改查就不再记录
我们来看一下 如何创建用户和让一个用户远程登录
CREATE USER test1@'192.168.43.84' IDENTIFIED BY 'test1';
#这里创建了一个指定ip为192.168.43.84的用户登录
username@'localhost' 只能本地连接
username@'192.168.43.84' 指定ip为192.168.43.84的用户连接
username@'192.168.43.%' 指定192.168.43.0这个网段的用户连接
#当然这时候该用户是没有特权的 做什么都不可以
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* to [email protected];
#为这个用户授予超级权限(类似于root)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
#刷新权限
3备份与恢复
备份
[root@hpb ~]# mysqldump -uroot -p mytest >/backup/mytest.dump
#后跟路径需要先创建好
恢复
mysql -u root -p123456 -t < mytest.dump