Linux安装mysql 及其使用

本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
  1. 配置基本信息
# 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                           ----》重新加载授权信息
  1. 启动 systemctl start mysqld 看状态 systemctl status mysqld 停止 service mysqld stop
  2. 配置远程登录
 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;         (刷新配置-->修改成功后必须执行此句)


  1. 新增用户访问指定库
grant all on 库名称.* to '用户名'@'允许登录的ip' identified by '密码';
flush privileges ;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值