系统版本:Red Hat Enterprise Linux Server release 6.8
mysql版本:mysql_8.0.15
安装准备:
从mysql官网下载mysqlrpm包,上传到服务器上。
[sgccroot@nezhdb02 ~]$ ll
total 527496
-rw-rw-r--. 1 sgccroot sgccroot 539678720 Mar 31 13:52 mysql-8.0.15-1.el6.x86_64.rpm-bundle.tar
解压后
[sgccroot@nezhdb02 ~]$ tar -xvf mysql-8.0.15-1.el6.x86_64.rpm-bundle.tar
mysql-community-libs-compat-8.0.15-1.el6.x86_64.rpm
mysql-community-test-8.0.15-1.el6.x86_64.rpm
mysql-community-devel-8.0.15-1.el6.x86_64.rpm
mysql-community-common-8.0.15-1.el6.x86_64.rpm
mysql-community-libs-8.0.15-1.el6.x86_64.rpm
mysql-community-client-8.0.15-1.el6.x86_64.rpm
mysql-community-server-8.0.15-1.el6.x86_64.rpm
检查系统是否有已安装mysql
如果有就会产生冲突
[sgccroot@nezhdb02 ~]$ rpm -qa | grep -i mariadb
[sgccroot@nezhdb02 ~]$ rpm -qa | grep -i mysql
mysql-libs-5.1.73-7.el6.x86_64
删除mysql-libs就可以正常安装,
[root@nezhdb02 ~]# rpm -e --nodeps mysql-libs-5.1.73-7.el6.x86_64
[root@nezhdb02 ~]# rpm -qa | grep mysql
安装:
依次安装4个包即可:
mysql-community-common-8.0.15-1.el6.x86_64.rpm
mysql-community-libs-8.0.15-1.el6.x86_64.rpm
mysql-community-client-8.0.15-1.el6.x86_64.rpm
mysql-community-server-8.0.15-1.el6.x86_64.rpm
[root@nezhdb02 mysql]# rpm -ivh mysql-community-common-8.0.15-1.el6.x86_64.rpm mysql-community-libs-8.0.15-1.el6.x86_64.rpm mysql-community-client-8.0.15-1.el6.x86_64.rpm mysql-community-server-8.0.15-1.el6.x86_64.rpm
warning: mysql-community-common-8.0.15-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-common ########################################### [ 25%]
2:mysql-community-libs ########################################### [ 50%]
3:mysql-community-client ########################################### [ 75%]
4:mysql-community-server ########################################### [100%]
warning: user mysql does not exist - using root
warning: group mysql does not exist - using root
warning: user mysql does not exist - using root
warning: group mysql does not exist - using root
warning: user mysql does not exist - using root
warning: group mysql does not exist - using root
warning: user mysql does not exist - using root
warning: group mysql does not exist - using root
建立mysql用户和组 ###应该提前就建好用户和组
[root@nezhdb02 etc]# groupadd mysql
[root@nezhdb02 etc]# useradd -g mysql mysql
启动并查看状态:
[root@nezhdb02 init.d]# ./mysqld start
MySQL Daemon failed to start.
Starting mysqld: [FAILED]
启动失败,查看mysql错误日志的位置:
[root@nezhdb02 lib]# cat /etc/my.cnf | grep -v ^#
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
查看mysql错误日志
[root@nezhdb02 lib]# vi /var/log/mysqld.log
发现对var/run/mysqld这个目录没有读写权限
2019-03-31T06:47:55.439110Z 0 [ERROR] [MY-013129] [Server] A message intended for a client cannot be sent there as no client-session is attached. Therefore, we're sending the information to the error-log instead: MY-000001 - Can't create/write to file '/var/run/mysqld/mysqld.pid' (OS errno 13 - Permission denied)
[root@nezhdb02 run]# ll /var/run/mysqld
drwxr-xr-x. 2 root root 4096 Jan 26 07:51 mysqld
应该是安装rpm包之前没有创建mysql用户和组的原因,接下来授权:
[root@nezhdb02 run]# service mysqld start
Starting mysqld: [ OK ]
登录mysql:
mysql安装的时候会生成一个临时root密码
[root@nezhdb02 run]# grep "password" /var/log/mysqld.log
2019-03-31T06:45:10.616344Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: zDKxko3i(kTs
[root@nezhdb02 run]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.15
Copyright (c) 2000, 2019, 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用户密码:
alter user root@'localhost' identified by 'Raid--Login19';
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
查看错误日志的信息时候会发现时区和北京时间的时区不一致,相差八个小时,不太习惯于平常的日志查看:
mysql> select sysdate from dual;
2019-03-31T07:05:50.424699Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.15) starting as process 30422
2019-03-31T07:05:51.546280Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2019-03-31T07:05:51.597288Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.15' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL.
2019-03-31T07:05:51.865492Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
此时需要参数为:
mysql> set global log_timestamps=system;
Query OK, 0 rows affected (0.00 sec)
不过若要重启MySQL生效的话还需要写到配置文件my.cnf
开放数据库远程登录
mysql> create user 'user1'@'%' identified by 'user1';
Query OK, 0 rows affected (0.07 sec)
mysql> grant all on *.* to 'user1'@'%' with grant option;
Query OK, 0 rows affected (0.06 sec)
mysql> exit
Bye
[mysql@nezhdb02 ~]$ mysql -h10.163.24.34 -uuser1 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.15 MySQL Community Server - GPL
Copyright (c) 2000, 2019, 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>