Centos7上mysql5.7.21版本安装

Mysql5.7.21安装

1、下载mysql5.7.21通用二进制版

wget http://172.16.6.100:8080/linux/mysql/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz

2、卸载系统自带的MariaDB

[root@CentOS ~]# rpm -qa | grep mariadb 
mariadb-libs-5.5.52-1.el7.x86_64
[root@CentOS ~]# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64 

3、创建mysql用户组和mysql用户

 [root@CentOS local]# useradd mysql  

4、解压安装包,并将解压好的文件夹重命名为mysql

[root@CentOS local]# tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
[root@CentOS local]# mv mysql-5.7.21-linux-glibc2.12-x86_64 mysql

  5、将mysql添加为系统服务

[root@CentOS local]# cp mysql/support-files/mysql.server /etc/init.d/mysql
[root@CentOS local]# chkconfig --add mysql
[root@CentOS local]# cp -r mysql /usr/local/ ####非常重要,必须做

6、初始化数据库

[root@CentOS mysql]# mkdir data
[root@CentOS mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2018-02-24T11:03:47.265873Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).  
2018-02-24T11:03:48.343129Z 0 [Warning] InnoDB: New log files created, LSN=45790  
2018-02-24T11:03:48.473269Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.  
2018-02-24T11:03:48.541782Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 63b1ed0c-1952-11e8-aa97-000c29847b2d.  
2018-02-24T11:03:48.542867Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.  
2018-02-24T11:03:48.543383Z 1 [Note] A temporary password is generated for root@localhost: =u>yyVorV7g% 
[root@CentOS mysql]#   

 如上所示,在/usr/local/mysql目录下创建用于保存数据的data 目录,初始化数据库后获得的临时密码为:=u>yyVorV7g%

7、启动mysql服务,使用临时密码登录mysql

[root@CentOS mysql]# systemctl start mysql
[root@CentOS mysql]# ./bin/mysql -u root -p 
Enter password:                     # 这里输入刚获取的临时密码 
Welcome to the MySQL monitor.  Commands end with ; or \g.  
Your MySQL connection id is 2  
Server version: 5.7.21  
Copyright (c) 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> 

8、修改登录密码

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');    # 将 root 登录密码修改为123456 
Query OK, 0 rows affected, 1 warning (0.00 sec) 
mysql>

9、将mysql服务设置为开机启动

[root@CentOS mysql]# chkconfig mysql on

  10、设置任何远程主机都可以访问数据库

[root@CentOS bin]# ./mysql -uroot -p123456
mysql> grant all privileges on *.* to 'root' @'%' identified by '123456';    # 设置任何远程主机都可以访问
mysql> flush privileges;                # 刷新权限

11、关闭防火墙,避免因为防火墙开着影响其它主机访问数据库的3306端口

[root@CentOS bin]#systemctl stop firewalld

 12、添加数据库和用户名密码

create database dep CHARACTER SET gbk COLLATE gbk_chinese_ci;  #数据库名根据实际情况修改
grant all privileges on dep.* to dep@'localhost' identified by '123456';  #用户名密码根据实际情况修改
grant all privileges on dep.* to dep@'%' identified by '123456'; #用户名密码根据实际情况修改

13、在windows下使用Sqlyog进行客户端测试是否可以登录数据库

常见问题:

1.mysql5.7远程登录不上

解决方法:

在/etc/my.cnf配置文件增加配置

[client]
default-character-set=utf8
bind-address = 0.0.0.0

[mysql]
socket=/var/lib/mysql/mysql.sock

[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock
lower_case_table_names=1 
max_connections=3000
binlog_cache_size=32m
max_binlog_cache_size=512m
max_binlog_size=512m
expire_logs_days=3
symbolic-links=0
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

配置后重启mysql数据库

2.创建数据库表时报错:

create trigger for http_log_ext error You do not have the SUPER privilege and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)

原因时因为配置了数据库主备同步,单机时一般不会出现这样的问题。

解决方法:

在配置文件中增加配置

log_bin_trust_function_creators=1

猜你喜欢

转载自blog.csdn.net/tl4832194/article/details/82224195
今日推荐