Mysql-5.7安装
安装前说明
如果机器上已经有了mysql或者MariaDB,先卸载再安装;
[root@lyucan ~]# rpm -e mariadb-libs-5.5.41-2.el7_0.x86_64 --nodeps
创建mysql用户
[root@lyucan ~]# useradd mysql
下载软件包并解压授权
[root@lyucan ~]# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
[root@lyucan ~]# tar -xf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@lyucan ~]# mv /usr/local/mysql-5.7.21-linux-glibc2.12-x86_64/ /usr/local/mysql
[root@lyucan ~]# chown mysql:mysql /usr/local/mysql/
创建数据目录
[root@lyucan ~]# mkdir /data/mysql -p
[root@lyucan ~]# chown -R mysql:mysql /data/mysql/
创建my.cnf配置文件
mysql5.7没有默认的my_default.cnf文件,需要自己手动创建,下面这个是一个简单的模板;
[root@lyucan mysql]# vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/data/mysql/
socket=/tmp/mysql.sock
log-error=/usr/local/mysql/mysqld.err
pid-file=/usr/local/mysql/mysqld.pid
#不区分大小写
lower_case_table_names = 1
#
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
#
max_connections=5000
修改my.cnf权限
[mysql@lyucan ~]$ chown mysql:mysql /etc/my.cnf
初始化数据
[root@lyucan bin]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
#这条命令没有输出,但是会创建一个临时的root密码,在上面配置文件定义的/usr/local/mysql/mysqld.err文件中,如下所示,临时密码为 5SEAgHPPqK<u
[root@lyucan ~]# cat /usr/local/mysql/mysqld.err
2018-04-08T16:39:16.991943Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-04-08T16:39:17.284209Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-04-08T16:39:17.337845Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-04-08T16:39:17.395477Z 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: 61308035-3b4b-11e8-9bb4-da8255dea6c5.
2018-04-08T16:39:17.396765Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-04-08T16:39:17.397767Z 1 [Note] A temporary password is generated for root@localhost: 5SEAgHPPqK<u
启动mysql
[root@lyucan support-files]# cd /usr/local/mysql/support-files/
[root@lyucan support-files]# ./mysql.server start
Starting MySQL. SUCCESS!
连接mysql
[root@lyucan support-files]# cd /usr/local/mysql/bin/
[root@lyucan bin]# ./mysql -uroot -p
Enter password: ##这里的密码就是上面的临时root密码 5SEAgHPPqK<u
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
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>
修改root密码
mysql> set password=password('root123');
Query OK, 0 rows affected, 1 warning (0.00 sec)
安装后操作
设置开机自启动
[root@lyucan bin]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@lyucan bin]# chkconfig --add mysqld
[root@lyucan bin]# chkconfig mysqld on
当复制到/etc/init.d/mysqld后,可以使用service mysqld start|stop的方式启停
[root@lyucan bin]# service mysqld status
SUCCESS! MySQL running (25732)
[root@lyucan bin]# service mysqld stop
Shutting down MySQL.. SUCCESS!
[root@lyucan bin]# service mysqld start
Starting MySQL. SUCCESS!
将mysql工具的命令添加到PATH环境变量里面去,使用的时候就不用使用绝对路径
[root@lyucan bin]# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@lyucan bin]# source /etc/profile
创建远程连接用户
mysql> grant all privileges on *.* to 'lyucan'@'%' identified by 'echo123.';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
远程连接检测,注意放通或关掉防火墙;
[root@lyucan ~]# firewall-cmd --permanent --add-service=mysql
success
[root@lyucan ~]# firewall-cmd --reload
success
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 289211569@qq.com