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

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: 最近由于要用到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的安装过程就结束了.

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
1天前
|
关系型数据库 MySQL Linux
Linux联网安装MySQL Server
Linux联网安装MySQL Server
7 0
|
2天前
|
关系型数据库 MySQL Linux
centos7安装mysql-带网盘安装包
centos7安装mysql-带网盘安装包
21 2
|
6天前
|
关系型数据库 MySQL 数据安全/隐私保护
MySQL 安装及连接
MySQL 安装及连接
23 0
|
8天前
|
关系型数据库 MySQL 数据库
docker自定义安装mysql 5.7
docker自定义安装mysql 5.7
17 0
|
8天前
|
关系型数据库 MySQL Linux
CentOS 7 下使用yum安装MySQL5.7.20 最简单 图文详解
CentOS 7 下使用yum安装MySQL5.7.20 最简单 图文详解
42 0
|
9天前
|
关系型数据库 MySQL 数据库
mysql卸载、下载、安装(window版本)
mysql卸载、下载、安装(window版本)
|
1月前
|
关系型数据库 MySQL 数据库连接
关于MySQL-ODBC的zip包安装方法
关于MySQL-ODBC的zip包安装方法
|
1月前
|
关系型数据库 MySQL Python
python安装MySQL-python:EnvironmentError解决办法
python安装MySQL-python:EnvironmentError解决办法
29 1
|
1月前
|
SQL 关系型数据库 MySQL
【MySQL】— —熟练掌握用SQL语句实现数据库和基本表的创建。熟练掌握MySQL的安装、客户端登录方法;熟练掌握MySQL的编码、数据类型等基础知识;掌握实体完整性的定义和维护方法、掌握参照完整性
【MySQL】— —熟练掌握用SQL语句实现数据库和基本表的创建。熟练掌握MySQL的安装、客户端登录方法;熟练掌握MySQL的编码、数据类型等基础知识;掌握实体完整性的定义和维护方法、掌握参照完整性
99 1
|
28天前
|
关系型数据库 MySQL 数据库
rds安装数据库客户端工具
安装阿里云RDS的数据库客户端涉及在本地安装对应类型(如MySQL、PostgreSQL)的客户端工具。对于MySQL,可选择MySQL Command-Line Client或图形化工具如Navicat,安装后输入RDS实例的连接参数进行连接。对于PostgreSQL,可以使用`psql`命令行工具或图形化客户端如PgAdmin。首先从阿里云控制台获取连接信息,然后按照官方文档安装客户端,最后配置客户端连接以确保遵循安全指引。
81 1