centos7安装mysql5.6.38史上最详细的安装步骤

本文涉及的产品
RDS AI 助手,专业版
RDSClaw,2核4GB
RDS DuckDB + QuickBI 企业套餐,8核32GB + QuickBI 专业版
简介: 最近由于要用到mysql,就想着装一个mysql,但是因为我的虚拟机是centos7的,centos7将默认数据库mysql替换成了Mariadb安装起来就比较的麻烦,遇到各种各样的问题,网上的教程很多,但是基本没有好使的,按照他们的步骤到最后没有一个成功的,搞了很长时间才装好,我记得之前在centos6.5上面安装也没那么复杂啊,但是在7上面不管是用yum方式,还是安装包的方式都搞了好几遍,最后用安装包的方式安装成功了,今天就来总结一下安装的过程.为了方便大家看整个过程,我又重新装了一遍.过程写的比较详细,建议大家先收藏在观看.

最近由于要用到mysql,就想着装一个mysql,但是因为我的虚拟机是centos7的,centos7将默认数据库mysql替换成了Mariadb安装起来就比较的麻烦,遇到各种各样的问题,网上的教程很多,但是基本没有好使的,按照他们的步骤到最后没有一个成功的,搞了很长时间才装好,我记得之前在centos6.5上面安装也没那么复杂啊,但是在7上面不管是用yum方式,还是安装包的方式都搞了好几遍,最后用安装包的方式安装成功了,今天就来总结一下安装的过程.为了方便大家看整个过程,我又重新装了一遍.过程写的比较详细,建议大家先收藏在观看.


1.下载安装包,我用的是5.6.38这个版本,最好是去官网下载.


2.检查是否安装过mysql,如果有先卸载, rpm -qa|grep -i mysql


用yum -y remove删除,如果有多个,一个一个执行,卸载不掉的用 rpm -ev


然后执行find / -name mysql|xargs rm -rf 删除所有mysql的文件夹


3.卸载系统自带的Mariadb


[root@storm2 ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@storm2 ~]#


卸载:rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64,再次执行查看发现已经不存在mariadb了.


4.删除etc目录下的my.cnf


[root@storm2 ~]# rm /etc/my.cnf


5.创建mysql用户组并且创建一个用户名为mysql的用户并加入mysql用户组


[root@storm2 ~]# groupadd mysql
[root@storm2 ~]# useradd -g mysql mysql


6.把下载的压缩包上传到 /usr/local/ 目录下


[root@storm2 ~]# cd /usr/local/
[root@storm2 local]# ll
total 321036
drwxr-xr-x. 2 root root         6 Nov  5  2016 bin
drwxr-xr-x. 2 root root         6 Nov  5  2016 etc
drwxr-xr-x. 2 root root         6 Nov  5  2016 games
drwxr-xr-x. 2 root root         6 Nov  5  2016 include
drwxr-xr-x. 2 root root         6 Nov  5  2016 lib
drwxr-xr-x. 2 root root         6 Nov  5  2016 lib64
drwxr-xr-x. 2 root root         6 Nov  5  2016 libexec
-rw-r--r--. 1 root root 328739574 Jan  3  2018 mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz
drwxr-xr-x. 2 root root         6 Nov  5  2016 sbin
drwxr-xr-x. 5 root root        49 Dec 26  2017 share
drwxr-xr-x. 2 root root         6 Nov  5  2016 src


7.解压tar包,并重命名.


tar -zxvf mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz 
mv mysql-5.6.38-linux-glibc2.12-x86_64 mysql


8.复制一份/usr/local/mysql/support-files/下的my-default.cnf文件到/etc下面.


cp support-files/my-default.cnf /etc/my.cnf


9.配置/etc目录下的my.cnf文件,vi /etc/my.cnf


[mysql]
# 设置mysql客户端默认字符集
character-set-server=utf8  
socket=/var/lib/mysql/mysql.sock
[mysqld]
skip-name-resolve
#设置3306端口
port = 3306 
socket=/var/lib/mysql/mysql.sock
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_name=1
max_allowed_packet=16M


10.进入安装mysql目录,给mysql用户赋权限.


[root@master mysql]# cd /usr/local/mysql/
[root@master mysql]# chown -R mysql:mysql ./


11.安装数据库


[root@storm2 mysql]#  ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ 
Installing MySQL system tables...2019-01-12 03:33:15 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-01-12 03:33:15 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2019-01-12 03:33:15 0 [Note] /usr/local/mysql//bin/mysqld (mysqld 5.6.38) starting as process 3620 ...
2019-01-12 03:33:15 3620 [Note] InnoDB: Using atomics to ref count buffer pool pages
2019-01-12 03:33:15 3620 [Note] InnoDB: The InnoDB memory heap is disabled
2019-01-12 03:33:15 3620 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-01-12 03:33:15 3620 [Note] InnoDB: Memory barrier is not used
2019-01-12 03:33:15 3620 [Note] InnoDB: Compressed tables use zlib 1.2.3
2019-01-12 03:33:15 3620 [Note] InnoDB: Using Linux native AIO
2019-01-12 03:33:15 3620 [Note] InnoDB: Using CPU crc32 instructions
2019-01-12 03:33:15 3620 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2019-01-12 03:33:16 3620 [Note] InnoDB: Completed initialization of buffer pool
2019-01-12 03:33:16 3620 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2019-01-12 03:33:16 3620 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2019-01-12 03:33:16 3620 [Note] InnoDB: Database physically writes the file full: wait...
2019-01-12 03:33:16 3620 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2019-01-12 03:33:17 3620 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2019-01-12 03:33:17 3620 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2019-01-12 03:33:17 3620 [Warning] InnoDB: New log files created, LSN=45781
2019-01-12 03:33:17 3620 [Note] InnoDB: Doublewrite buffer not found: creating new
2019-01-12 03:33:17 3620 [Note] InnoDB: Doublewrite buffer created
2019-01-12 03:33:17 3620 [Note] InnoDB: 128 rollback segment(s) are active.
2019-01-12 03:33:17 3620 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-01-12 03:33:17 3620 [Note] InnoDB: Foreign key constraint system tables created
2019-01-12 03:33:17 3620 [Note] InnoDB: Creating tablespace and datafile system tables.
2019-01-12 03:33:17 3620 [Note] InnoDB: Tablespace and datafile system tables created.
2019-01-12 03:33:17 3620 [Note] InnoDB: Waiting for purge to start
2019-01-12 03:33:17 3620 [Note] InnoDB: 5.6.38 started; log sequence number 0
2019-01-12 03:33:18 3620 [Note] Binlog end
2019-01-12 03:33:18 3620 [Note] InnoDB: FTS optimize thread exiting.
2019-01-12 03:33:18 3620 [Note] InnoDB: Starting shutdown...
2019-01-12 03:33:19 3620 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
Filling help tables...2019-01-12 03:33:19 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-01-12 03:33:19 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2019-01-12 03:33:19 0 [Note] /usr/local/mysql//bin/mysqld (mysqld 5.6.38) starting as process 3645 ...
2019-01-12 03:33:19 3645 [Note] InnoDB: Using atomics to ref count buffer pool pages
2019-01-12 03:33:19 3645 [Note] InnoDB: The InnoDB memory heap is disabled
2019-01-12 03:33:19 3645 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-01-12 03:33:19 3645 [Note] InnoDB: Memory barrier is not used
2019-01-12 03:33:19 3645 [Note] InnoDB: Compressed tables use zlib 1.2.3
2019-01-12 03:33:19 3645 [Note] InnoDB: Using Linux native AIO
2019-01-12 03:33:19 3645 [Note] InnoDB: Using CPU crc32 instructions
2019-01-12 03:33:19 3645 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2019-01-12 03:33:19 3645 [Note] InnoDB: Completed initialization of buffer pool
2019-01-12 03:33:20 3645 [Note] InnoDB: Highest supported file format is Barracuda.
2019-01-12 03:33:20 3645 [Note] InnoDB: 128 rollback segment(s) are active.
2019-01-12 03:33:20 3645 [Note] InnoDB: Waiting for purge to start
2019-01-12 03:33:20 3645 [Note] InnoDB: 5.6.38 started; log sequence number 1625977
2019-01-12 03:33:20 3645 [Note] Binlog end
2019-01-12 03:33:20 3645 [Note] InnoDB: FTS optimize thread exiting.
2019-01-12 03:33:20 3645 [Note] InnoDB: Starting shutdown...
2019-01-12 03:33:21 3645 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
  /usr/local/mysql//bin/mysqladmin -u root password 'new-password'
  /usr/local/mysql//bin/mysqladmin -u root -h storm2 password 'new-password'
Alternatively you can run:
  /usr/local/mysql//bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
  cd . ; /usr/local/mysql//bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
  cd mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
 http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as /usr/local/mysql//my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server


12.修改当前data目录的拥有者为mysql用户


[root@storm2 mysql]# chown -R mysql:mysql data


13.授予my.cnf最大权限


[root@storm2 mysql]# chmod 777 /etc/my.cnf


14.设置开机自启动服务控制脚本:


[root@storm2 mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld


15.增加mysqld服务控制脚本执行权限


[root@storm2 mysql]# chmod +x /etc/rc.d/init.d/mysqld


16.将mysqld服务加入到系统服务,并检查mysqld服务是否生效,出现下图所示,表示已经生效


[root@storm2 mysql]# chkconfig --add mysqld
[root@storm2 mysql]# chkconfig --list mysqld
Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.
      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.
mysqld          0:off 1:off 2:on  3:on  4:on  5:on  6:off


17,最后启动mysql.


[root@storm2 mysql]# service mysqld start
Warning: World-writable config file '/etc/my.cnf' is ignored
Starting MySQL.Warning: World-writable config file '/etc/my.cnf' is ignored
Warning: World-writable config file '/etc/my.cnf' is ignored
Logging to '/usr/local/mysql/data/storm2.err'.
....... SUCCESS!


18,以root账户登录mysql,默认是没有密码的


[root@storm2 bin]# mysql -uroot -p
Warning: World-writable config file '/etc/my.cnf' is ignored
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.38 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>


要输入密码的时候直接回车即可。


19.修改密码


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 password=password('12345678') where user='mysql' and host='localhost';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


20.设置远程主机登录,不然在连接的时候会报错


mysql> GRANT ALL PRIVILEGES ON *.* TO 'mysql'@'%' IDENTIFIED BY '12345678' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)


到这整个mysql的安装过程就结束了.

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
相关文章
|
6月前
|
Ubuntu 关系型数据库 MySQL
MySQL源码编译安装
本文详细介绍了MySQL 8.0及8.4版本的源码编译安装全过程,涵盖用户创建、依赖安装、cmake配置、编译优化等步骤,并提供支持多Linux发行版的一键安装脚本,适用于定制化数据库部署需求。
1692 4
MySQL源码编译安装
|
6月前
|
Ubuntu 关系型数据库 MySQL
MySQL二进制包安装
本文详细介绍了在多种Linux系统上通过二进制包安装MySQL 8.0和8.4版本的完整过程,涵盖用户创建、glibc版本匹配、程序解压、环境变量配置、初始化数据库及服务启动等步骤,并提供支持多发行版的一键安装脚本,助力高效部署MySQL环境。
930 4
MySQL二进制包安装
|
6月前
|
安全 关系型数据库 MySQL
MySQL包安装 -- SUSE系列(离线RPM包安装MySQL)
本文详细介绍在openSUSE系统上通过离线RPM包安装MySQL 8.0和8.4版本的完整步骤,包括下载地址、RPM包解压、GPG密钥导入、使用rpm或zypper命令安装及服务启动验证,涵盖初始密码获取与安全修改方法,适用于无网络环境下的MySQL部署。
706 3
MySQL包安装 -- SUSE系列(离线RPM包安装MySQL)
|
6月前
|
关系型数据库 MySQL Linux
MySQL包安装 -- SUSE系列(SUSE资源库安装MySQL)
本文介绍了在openSUSE系统上通过SUSE资源库安装MySQL 8.0和8.4版本的完整步骤,包括配置国内镜像源、安装MySQL服务、启动并验证运行状态,以及修改初始密码等操作,适用于希望在SUSE系列系统中快速部署MySQL的用户。
666 3
MySQL包安装 -- SUSE系列(SUSE资源库安装MySQL)
|
6月前
|
NoSQL 算法 Redis
【Docker】(3)学习Docker中 镜像与容器数据卷、映射关系!手把手带你安装 MySql主从同步 和 Redis三主三从集群!并且进行主从切换与扩容操作,还有分析 哈希分区 等知识点!
Union文件系统(UnionFS)是一种**分层、轻量级并且高性能的文件系统**,它支持对文件系统的修改作为一次提交来一层层的叠加,同时可以将不同目录挂载到同一个虚拟文件系统下(unite several directories into a single virtual filesystem) Union 文件系统是 Docker 镜像的基础。 镜像可以通过分层来进行继承,基于基础镜像(没有父镜像),可以制作各种具体的应用镜像。
745 6
|
6月前
|
运维 Ubuntu 关系型数据库
MySQL包安装 -- Debian系列(Apt资源库安装MySQL)
本文介绍了在Debian系列系统(如Ubuntu、Debian 11/12)中通过APT仓库安装MySQL 8.0和8.4版本的完整步骤,涵盖添加官方源、配置国内镜像、安装服务及初始化设置,并验证运行状态,适用于各类Linux运维场景。
1957 0
MySQL包安装 -- Debian系列(Apt资源库安装MySQL)
|
7月前
|
缓存 关系型数据库 BI
使用MYSQL Report分析数据库性能(下)
使用MYSQL Report分析数据库性能
494 158
|
7月前
|
关系型数据库 MySQL 数据库
自建数据库如何迁移至RDS MySQL实例
数据库迁移是一项复杂且耗时的工程,需考虑数据安全、完整性及业务中断影响。使用阿里云数据传输服务DTS,可快速、平滑完成迁移任务,将应用停机时间降至分钟级。您还可通过全量备份自建数据库并恢复至RDS MySQL实例,实现间接迁移上云。
|
7月前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS费用价格:MySQL、SQL Server、PostgreSQL和MariaDB引擎收费标准
阿里云RDS数据库支持MySQL、SQL Server、PostgreSQL、MariaDB,多种引擎优惠上线!MySQL倚天版88元/年,SQL Server 2核4G仅299元/年,PostgreSQL 227元/年起。高可用、可弹性伸缩,安全稳定。详情见官网活动页。
1243 152
下一篇
开通oss服务