下载
Mysql 数据库的下载链接
注意:CenterOS 请选择 Red Hat 那一项!
安装
这里介绍的是 5.7 版本,安装包是 .rpm-bundle.tar 结尾的。
-
创建 mysql-install 目录,用来上传下载好的 .tar 文件。
-
查看 Cenos7 自带的 mariadb-lib,rpm -qa|grep mariadb
-
有 mariadb-lib,执行卸载,rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps
-
安装 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
-
初始化数据库,mysqld --initialize #初始化后会在/var/log/mysqld.log生成随机密码
-
修改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.
-
登录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)
-
重启mysql服务,systemctl restart mysqld.service
-
可能有些组件没有安装,解决如下。
- 缺少 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>
授权