下载安装包
[root@localhost ~]# yum install -y cmake make gcc gcc-c++ bison ncurses ncurses-
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# ll
total 626104
-rw-r--r--. 1 root root 641127384 Dec 7 18:13 mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
解压安装包
[root@localhost src]# tar -zxvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
拷贝到安装目录
[root@localhost src]# cp -r mysql-5.7.20-linux-glibc2.12-x86_64 /usr/local/mysql
创建数据库用户并受权
[root@localhost src]# groupadd mysql
[root@localhost src]# useradd -r -g mysql mysql
[root@localhost src]# cd /usr/local/mysql/
[root@localhost mysql]# chown -R mysql:mysql ./
开始安装到指定目录
[root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2018-12-07T10:17:02.880850Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-12-07T10:17:03.111319Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-12-07T10:17:03.190424Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-12-07T10:17:03.271952Z 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: 3dc4380e-fa09-11e8-aa65-000c299e4e76.
2018-12-07T10:17:03.273379Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-12-07T10:17:03.274745Z 1 [Note] A temporary password is generated for root@localhost: jxynC!xpj6qq--------此处是mysql的初始密码,下面登陆时使用
[root@localhost mysql]# bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
对数据文件授权
[root@localhost mysql]# chown -R mysql:mysql ./
[root@localhost mysql]# chown -R mysql:mysql data
第一次进行mysql用户设置配置文件
[root@localhost mysql]# vi /etc/my.cnf
拷贝下面内容
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
#不区分大小写 (sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 这个简单来说就是sql语句是否严格)
lower_case_table_names = 1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/usr/local/mysql/data/mysqld.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
#添加开机启动
[root@localhost mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
重启服务
[root@localhost mysql]# service mysqld start
Starting MySQL. SUCCESS!
加入开机起动
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
进入数据库
登录修改密码 mysql -uroot -p 上面初始化时的密码
如果出现错误 需要添加软连接 ln -s /usr/local/mysql/bin/mysql /usr/bin
ln -s /usr/local/mysql/bin/mysql /usr/bin
[root@localhost ~]# mysql -uroot -p
Enter password: -------------------------------------------------------------------->此处需使用上面初始化的密码来登陆。
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.20 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> set password for 'root'@'localhost' = password('新密码');
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> set password for 'root'@'localhost' = password('root123');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
登陆
[root@localhost ~]# mysql -uroot -proot123;