本linux系统为 7.3
查看是否有自带的mariadb
# rpm -qa|grep mariadb
若出现 mariadb-libs-5.5.52-1.el7.x86_64 表明存在 需要卸载 见 2
卸载自带的 mariadb
# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64 (注:版本号改成实际的)
1. # rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
2. # yum repolist enabled | grep "mysql.*-community.*"
3. # yum install mysql-community-server
4. 中间安装软件一直:y
5. 启动mysql:systemctl start mysqld 也可以用 service mysqld start
- 配置基本信息
# mysql_secure_installation
Enter current password for root (enter for none): ----》默认为空密码直接回车
Set root password? [Y/n] y ----》设置root密码
New password:
Re-enter new password:
Remove anonymous users? [Y/n] y ----》禁止匿名访问
Disallow root login remotely? [Y/n] y ----》不允许root远程访问
Remove test database and access to it? [Y/n] y ----》删除测试数据库test
Reload privilege tables now? [Y/n] y ----》重新加载授权信息
- 启动 systemctl start mysqld 看状态 systemctl status mysqld 停止 service mysqld stop
- 配置远程登录
1:# mysql -u root -p
Enter password: (输入密码并回车,输入密码时并没有提示)
mysql> use mysql;
mysql> select host ,user from user (查询当前的用户和ip 如下)
+-----------+------+
| host | user |
+-----------+------+
| 127.0.0.1 | root |
| ::1 | root |
| localhost | root |
+-----------+------+
2:root此时只能本机登陆 可以将root设置为远程登陆 ,也可以新增用户远程登陆
8-1:配置root为远程登陆
mysql> update user set host='%' where user='root' and host='127.0.0.1'; (提示下面信息就表示修改成功了)
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges; (刷新配置-->修改成功后必须执行此句)
8-2:新增用户[user]远程登陆,密码为[123456]
mysql> GRANT ALL PRIVILEGES ON *.* TO 'user'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql> flush privileges; (刷新配置-->修改成功后必须执行此句)
- 新增用户访问指定库
grant all on 库名称.* to '用户名'@'允许登录的ip' identified by '密码';
flush privileges ;