在官网:http://dev.mysql.com/downloads/mysql/ 中,选择以下版本的mysql下载:
1、解压压缩包到目标位置
--解压压缩包[root@ecs-1b35-0002 tools]# tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
--移动并修改文件名[root@ecs-1b35-0002 tools]# mv mysql-5.7.25-linux-glibc2.12-x86_64 ../yoodb/mysql
[root@ecs-1b35-0002 mysql]# pwd
/home/yoodb/mysql
2、创建数据仓库目录[root@ecs-1b35-0002 mysql]# mkdir data/mysql
新建mysql用户、组及目录[root@ecs-1b35-0002 mysql]# groupadd mysql
[root@ecs-1b35-0002 mysql]# useradd -r -s /sbin/nologin -g mysql mysql -d /home/yoodb/mysql
3、改变目录属有者[root@ecs-1b35-0002 mysql]# chown -R mysql .
[root@ecs-1b35-0002 mysql]# chgrp -R mysql .
[root@ecs-1b35-0002 mysql]# chown -R mysql /data/mysql
[root@ecs-1b35-0002 data]# cd ..
[root@ecs-1b35-0002 mysql]# chown -R mysql data/mysql
[root@ecs-1b35-0002 mysql]# ls
bin COPYING data docs include lib man README share support-files
4、配置参数
[root@ecs-1b35-0002 mysql]# bin/mysqld --initialize --user=mysql --basedir=/home/yoodb/mysql --datadir=/home/yoodb/mysql/data/mysql2019-01-28T07:37:54.141689Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-01-28T07:37:54.468955Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-01-28T07:37:54.533436Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-01-28T07:37:54.599965Z 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: 9fcb80c7-22cf-11e9-92c7-fa163ef336d3.
2019-01-28T07:37:54.602975Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-01-28T07:37:54.603403Z 1 [Note] A temporary password is generated for root@localhost: q0_wqowE8gk5
此处需要注意记录生成的临时密码,如上文结尾处的:q0_wqowE8gk5
5、使用脚本工具生成密钥文件
[root@ecs-1b35-0002 mysql]# bin/mysql_ssl_rsa_setup --datadir=/home/yoodb/mysql/data/mysqlGenerating a 2048 bit RSA private key
......................................................................+++
..................+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
..................................................................................+++
....................................................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
...............................................+++
....................................+++
writing new private key to 'client-key.pem'
-----
6、修改系统配置文件[root@ecs-1b35-0002 mysql]# cd support-files/
[root@ecs-1b35-0002 support-files]# ls
magic mysqld_multi.server mysql-log-rotate mysql.server
[root@ecs-1b35-0002 support-files]# cp mysql.server /etc/init.d/mysql
7、修改以下内容
[root@ecs-1b35-0002 mysql]# vi /etc/my.cnf
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
port=3307
datadir=/home/zkjc/mysql/data/mysql
skip-grant-tables
[root@ecs-1b35-0002 mysql]# /etc/init.d/mysql start
Starting MySQL.Logging to '/home/yoodb/mysql/data/mysql/ecs-1b35-0002.novalocal.err'.
SUCCESS!
8、启动mysql[root@ecs-1b35-0002 mysql]# ln -s /home/yoodb/mysql/bin/mysql /usr/bin
[root@ecs-1b35-0002 my.cnf.d]# service mysql start
[root@ecs-1b35-0002 mysql]# mysql -hlocalhost -uroot -p
Enter password: 输入生成的临时密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25
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> set password=password('yoodb123!@#');
Query OK, 0 rows affected, 1 warning (0.00 sec)
--设置root账户的host地址(修改可以远程连接)
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit;
Bye
这样就可以使用远程连接数据了。
9、添加系统路径
# vim /etc/profile
添加:export PATH=/home/yoodb/mysql/bin:$PATH
[root@ecs-1b35-0002 mysql]# source /etc/profile
10、配置mysql自动启动[root@ecs-1b35-0002 mysql]# chmod 755 /etc/init.d/mysql
[root@ecs-1b35-0002 mysql]# chkconfig --add mysql
[root@ecs-1b35-0002 mysql]# chkconfig --level 345 mysql on