centos7 安装mysql

1.查看系统中是否已安装 MySQL 服务

#rpm -qa | grep mysql
#yum list installed | grep mysql

如果已经有安装的,用命令删掉

#yum -y remove ...

2.下载安装

#wget http://repo.mysql.com/mysql57-community-release-el7-9.noarch.rpm  //下载
#rpm -ivh mysql57-community-release-el7-9.noarch.rpm
#yum install mysql-server  //一路选y,直到安装完成

3.配置

安装完毕后,在 /var/log/mysqld.log 文件中会自动生成一个随机的密码,需要先取得这个随机密码

#grep "password" /var/log/mysqld.log
2017-08-06T04:23:22.939636Z 1 [Note] A temporary password is generated for root@localhost: aZqHg=eQG9Nq

使用临时密码登陆mysql并更新用户 root 的密码

#[root@iZjafzbmqur2lzZ ~]# mysql -u root -paZqHg=eQG9Nq
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 5
Server version: 5.7.19

Copyright (c) 2000, 2017, 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> 

打印以上信息表示登陆成功,设置用户 root 可以在任意 IP 下被访问:

mysql> set password = password('新密码');
mysql> grant all privileges on *.* to root@"%" identified by "新密码";  //设置用户 root 可以在任意 IP 下被访问
mysql> grant all privileges on *.* to root@"localhost" identified by "新密码";
mysql> show databases;  //查看当前都内置了哪些数据库
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> exit  //退出

4. 启动

#service mysqld start     //启动 MySQL 服务
#service mysqld restart   //重启 MySQL 
#ervice mysqld status     //查看 MySQL 的状态

5. 忘记密码时,可用如下方法重置:

#service mysqld stop
# mysqld_safe --user=root --skip-grant-tables --skip-networking &
# mysql -u root 
mysql> use mysql;
mysql> update user set password=password("new_password") where user="root"; 
mysql> flush privileges;
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值