CentOS6安装mysql-5.7.28

下载不需要编译的包

这里使用的操作系统是CentOS6,64位操作系统

$ wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz

解压后放在某个目录下

$ tar zxf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
$ mkdir -p ~/3rd/mysql-5.7.28
$ mv mysql-5.7.28-linux-glibc2.12-x86_64/* ~/3rd/mysql-5.7.28

创建目录

提前创建一个目录可以提前创建,如:

$ mkdir /home/testerzhang/3rd/mysqll-5.7.28/data/
$ mkdir /home/testerzhang/3rd/mysqll-5.7.28/log/

初始化data

假设当前用户名是testerzhang

$ cd ~/3rd/mysql-5.7.28
$ ./bin/mysql_install_db --user=testerzhang --basedir=/home/testerzhang/3rd/mysqll-5.7.28 --datadir=/home/testerzhang/3rd/mysqll-5.7.28/data

日志输出

2019-10-31 12:30:59 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2019-10-31 12:31:20 [WARNING] The bootstrap log isn't empty:
2019-10-31 12:31:20 [WARNING] 2019-10-31T04:30:59.852748Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2019-10-31T04:30:59.853622Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2019-10-31T04:30:59.853634Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)

创建配置文件

$ vim bin/my.cnf 
[mysqld]
datadir=/home/testerzhang/3rd/mysqll-5.7.28/data
basedir=/home/testerzhang/3rd/mysqll-5.7.28
socket=/home/testerzhang/3rd/mysqll-5.7.28/bin/mysql.sock
user=testerzhang
port=3306
character-set-server=utf8

#跳过密码验证,忘记密码 可以设置,然后修改密码,再关闭
skip-grant-tables

# 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=/home/testerzhang/3rd/mysqll-5.7.28/log/mysqld.log
pid-file=/home/testerzhang/3rd/mysqll-5.7.28/bin/mysqld.pid

写个启动脚本

$ cd ~/3rd/mysql-5.7.28/bin
$ vim startmysql.sh 
./mysqld_safe --defaults-file=./my.cnf &

$ sh -x startmysql.sh 

初次设置root密码

$ mysql -h127.0.0.1 -P3306 -uroot -p   
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28 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> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set authentication_string=password('具体密码') where user='root';        
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye

修改密码后用密码登录再次设置root密码

mysql> use mysql
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> alter user 'root'@'localhost' identified by '具体密码';
Query OK, 0 rows affected (0.00 sec)

设置root可以远程被连接(此步可以不做)

mysql> use mysql
mysql> update user set host='%' where user = 'root';
mysql> flush privileges;
mysql> exit;

创建普通用户

如创建一个test用户,密码为test123,可以进行远程登录:

mysql>grant all privileges on test.* to 'test'@'%' identified by 'test123';

你可能感兴趣的:(CentOS6安装mysql-5.7.28)