Mysql 学习

下载

Mysql 数据库的下载链接

注意:CenterOS 请选择 Red Hat 那一项!

安装

这里介绍的是 5.7 版本,安装包是 .rpm-bundle.tar 结尾的。

  1. 创建 mysql-install 目录,用来上传下载好的 .tar 文件。

  2. 查看 Cenos7 自带的 mariadb-lib,rpm -qa|grep mariadb

  3. 有 mariadb-lib,执行卸载,rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps

  4. 安装 mysql-server 服务
    rpm -ivh mysql-community-common-5.7.23-1.el7.x86_64.rpm
    rpm -ivh mysql-community-libs-5.7.23-1.el7.x86_64.rpm
    rpm -ivh mysql-community-client-5.7.23-1.el7.x86_64.rpm
    rpm -ivh mysql-community-server-5.7.23-1.el7.x86_64.rpm

  5. 初始化数据库,mysqld --initialize #初始化后会在/var/log/mysqld.log生成随机密码

  6. 修改mysql数据库目录的所属用户及其所属组,然后启动mysql数据库

    [root@VM_0_16_centos mysql5.7.23]# chown mysql:mysql /var/lib/mysql -R
    [root@VM_0_16_centos mysql5.7.23]# systemctl start mysqld.service
    [root@VM_0_16_centos mysql5.7.23]# systemctl status mysqld.service
    ● mysqld.service - MySQL Server
    Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
    Active: active (running) since 一 2018-08-06 20:41:25 CST; 6s ago
    Docs: man:mysqld(8)
    http://dev.mysql.com/doc/refman/en/using-systemd.html
    Process: 13031 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
    Process: 13003 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
    Main PID: 13034 (mysqld)
    Tasks: 27
    CGroup: /system.slice/mysqld.service
    └─13034 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

    8月 06 20:41:22 eric111 systemd[1]: Starting MySQL Server…
    8月 06 20:41:25 eric111 systemd[1]: Started MySQL Server.

  7. 登录mysql,并修改root用户的密码(系统强制要求,否则不能操作mysql)

    [root@VM_0_16_centos mysql5.7.23]# mysql -uroot -p’-4iq<tyjVpLb’
    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 2
    Server version: 5.7.23

    Copyright © 2000, 2018, 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> set password=password(‘123456’);
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    mysql> flush privileges;
    Query OK, 0 rows affected (0.01 sec)

    mysql> show databases;
    ±-------------------+
    | Database |
    ±-------------------+
    | information_schema |
    | mysql |
    | performance_schema |
    | sys |
    ±-------------------+
    4 rows in set (0.00 sec)

  8. 重启mysql服务,systemctl restart mysqld.service

  9. 可能有些组件没有安装,解决如下。

    • 缺少 libaio,yum install libaio
    • 缺少 net-tools,yum install net-tools
    • 缺少 numactl,yum install numactl

修改

修改登录密码

> mysql> update user set host='%',authentication_string=password('123456') where user='root';
> Query OK, 0 rows affected, 1 warning (0.02 sec)
> Rows matched: 1  Changed: 0  Warnings: 1
> 
> mysql> flush privileges;
> Query OK, 0 rows affected (0.01 sec)
> 
> mysql>   

授权

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值