【MySQL】mysql-5.7.30 最新版本最全安装技巧!亲测亲为,绝对实用!!!

官方下载地址:

https://dev.mysql.com/downloads/mysql/
【MySQL】mysql-5.7.30 最新版本最全安装技巧!亲测亲为,绝对实用!!!_第1张图片
【MySQL】mysql-5.7.30 最新版本最全安装技巧!亲测亲为,绝对实用!!!_第2张图片

注意:

​ 如果以前使用操作系统本机软件包管理系统(例如Yum或APT)安装了MySQL,则在使用本机二进制文件安装时可能会遇到问题。确保以前的MySQL安装已完全删除(使用程序包管理系统),并且所有其他文件(例如数据文件的旧版本)也已删除。您还应该检查配置文件(例如/etc/my.cnf/etc/mysql目录)并删除它们

​ *对于MySQL 5.7.19和更高版本:*通用Linux版本中增加了对非统一内存访问(NUMA)的支持,该版本现在对libnuma库具有依赖关系 。如果您的系统上尚未安装该库,请使用系统的程序包管理器搜索并安装它 .

SLES 11:从MySQL 5.7.19开始,Linux Generic tarball软件包格式为EL6而不是EL5。副作用是,MySQL客户端 bin / mysql需要 libtinfo.so.5

​ 一种解决方法是创建一个符号链接,例如在64位系统上创建ln -s libncurses.so.5.6 /lib64/libtinfo.so.5或在32 位系统上创建ln -s libncurses.so.5.6 /lib/libtinfo.so.5位系统。

通用Unix / Linux二进制软件包的MySQL安装布局

目录 目录内容
bin mysqld服务器,客户端和实用程序
docs 信息格式的MySQL手册
man Unix手册页
include 包含(头)文件
lib 图书馆
share 错误消息,字典和用于数据库安装的SQL
support-files 杂项支持文件

安装步骤

  • 查看是否有mysql用户组和用户
[root@localhost local]# cat /etc/group | grep mysql 
[root@localhost local]# cat /etc/passwd | grep mysql
  • 没有则创建,有则跳过这步
[root@localhost local]# groupadd mysql
[root@localhost local]# useradd  -g mysql  mysql
[root@localhost local]# passwd mysql
  • 卸载自带的mariadb数据库
[root@localhost mysql]# rpm -qa|grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@localhost mysql]# rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
  • 删除my.cnf
[root@localhost mysql]# rm -rf /etc/my.cnf
  • 安装 libaio 依赖(最后的附录中有说明)
[root@localhost local]# yum install -y libaio 
  • 安装 lrzsz 文件传输插件
[root@localhost local]# yum install -y lrzsz
  • 上传 mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz 文件 + 解压缩 + 修改文件改名
[root@localhost ~]# cd /usr/local/
[root@localhost local]# rz
[root@localhost local]# tar -zxf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz 
[root@localhost local]# mv mysql-5.7.30-linux-glibc2.12-x86_64 mysql
  • 创建文件夹 data 并修改权限
[root@localhost local]# cd /usr/local/mysql
[root@localhost mysql]# mkdir data
[root@localhost mysql]# chown mysql:mysql data
[root@localhost mysql]# chmod 750 data
  • 修改环境变量
[root@localhost mysql]# vim /etc/profile
#添加
export PATH=$PATH:/usr/local/mysql/bin
  • 创建新的 my.cnf 配置文件
[root@localhost mysql]# vim /etc/my.cnf
#/etc/my.cnf 配置文件内容
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8

[mysqld]
# 设置启动用户
user=root
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库数据的存储目录
datadir=/usr/local/mysql/data
#设置3306端口
port = 3306
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB

[mysqld_safe]
user=root
  • 初始化(一定记住最后一行的12位密码
[root@localhost mysql]# bin/mysqld --initialize
2020-05-29T12:26:00.082613Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-05-29T12:26:00.327186Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-05-29T12:26:00.356061Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-05-29T12:26:00.410894Z 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: 8e1d2e37-a1a7-11ea-9509-000c29358161.
2020-05-29T12:26:00.411627Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-05-29T12:26:01.096292Z 0 [Warning] CA certificate ca.pem is self signed.
2020-05-29T12:26:01.324684Z 1 [Note] A temporary password is generated for root@localhost: ra?8;TDuc!4T
  • 开启mysql server
[root@localhost mysql]# bin/mysqld
  • 登录mysql修改密码并添加远程访问权限
[root@localhost mysql]# bin/mysql -uroot -p
Enter password: ra?8;TDuc!4T(前面初始化的时候产生的密码)
# 修改密码(mysql的安全策略,不修改无法进行操作)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
# 修改root用户可以远程访问
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
# 刷新
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
# 退出
mysql> quit
Bye!
  • 添加到系统服务
[root@localhost mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chown 777 /etc/my.cnf
[root@localhost mysql]# chmod +x /etc/init.d/mysqld
[root@localhost mysql]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS!

#之后就可以使用一下命令控制mysql服务了
[root@localhost mysql]# systemctl start mysqld
[root@localhost mysql]# systemctl status mysqld
[root@localhost mysql]# systemctl restart mysqld
[root@localhost mysql]# systemctl stop mysqld
  • 设置开机启动
[root@localhost mysql]# chkconfig --level 35 mysqld on
[root@localhost mysql]# chkconfig --list mysqld

[root@localhost mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig --list mysqld
[root@localhost mysql]# service mysqld status
 SUCCESS! MySQL running (4475)

部分内置功能使用测试

  • 查看版本信息
[root@localhost bin]# mysqladmin -u root -p version
Enter password: 
mysqladmin  Ver 8.42 Distrib 5.7.30, for linux-glibc2.12 on x86_64
Copyright (c) 2000, 2020, 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.

Server version		5.7.30
Protocol version	10
Connection		Localhost via UNIX socket
UNIX socket		/tmp/mysql.sock
Uptime:			10 min 8 sec

Threads: 2  Questions: 7  Slow queries: 0  Opens: 106  Flush tables: 1  Open tables: 99  Queries per second avg: 0.011
  • 查看数据库
[root@localhost ~]# mysqlshow -uroot -p
Enter password: 
+--------------------+
|     Databases      |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
  • 查看数据库中的表
[root@localhost ~]# mysqlshow mysql -uroot -p
Enter password: 
Database: mysql
+---------------------------+
|          Tables           |
+---------------------------+
| columns_priv              |
| db                        |
| engine_cost               |
| event                     |
| func                      |
| general_log               |
| gtid_executed             |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| server_cost               |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
  • 查询表中的数据
# 查看版本信息
[root@localhost ~]# mysql -e "SELECT User, Host, plugin FROM mysql.user" mysql -uroot -p 123456
  • 关闭mysql
[root@localhost ~]# mysqladmin -u root -p shutdown
Enter password: 

附录:

MySQL对libaio 库有依赖性。如果未在本地安装该库,则数据目录初始化和随后的服务器启动步骤将失败。

  • 失败案例(自己第一次安装的时候)
bin/mysql_install_db --user=root --basedir=/opt/software/mysql-5.7.30/ --datadir=/opt/software/mysql-5.7.30/data/
#result
2020-05-29 17:42:43 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2020-05-29 17:42:43 [ERROR]   Child process: /opt/software/mysql-5.7.30/bin/mysqldterminated prematurely with errno= 32
2020-05-29 17:42:43 [ERROR]   Failed to execute /opt/software/mysql-5.7.30/bin/mysqld --bootstrap --datadir=/opt/software/mysql-5.7.30/data --lc-messages-dir=/opt/software/mysql-5.7.30/share --lc-messages=en_US --basedir=/opt/software/mysql-5.7.30
-- server log begin --
/opt/software/mysql-5.7.30/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

-- server log end --

安装libaio

shell> yum install -y libaio # install library

你可能感兴趣的:(MySQL,数据库,mysql,centos)