云服务器配置CentOS 7.6(二)--安装mySQL

文章目录

  • 1. mysql下载地址
  • 2.下载mysql5.6
    • 2.1 在云服务器上下载mysql5.6
    • 2.2 先下载到本地磁盘。再上传到云服务器
  • 3.在安装之前,检查一下有没有系统自带的mysql相关的rpm文件,若有卸载掉
  • 4.开始安装--安装命令
  • 5.开启mysql服务并配置
    • 5.1 开启mysql服务和停止mysql服务
  • 6.设置自定义密码
  • 7开启远程服务
  • 8. MySQL的默认安装位置
  • 8.1修改配置文件位置
    • 8.2 数据库目录
    • 8.3 配置文件目录/usr/share/mysql
  • 9 修改字符集和数据存储路径
  • 10.问题说明

1. mysql下载地址

https://dev.mysql.com/downloads/mysql/5.6.html#downloads
云服务器配置CentOS 7.6(二)--安装mySQL_第1张图片
云服务器配置CentOS 7.6(二)--安装mySQL_第2张图片

2.下载mysql5.6

2.1 在云服务器上下载mysql5.6

wget https://cdn.mysql.com//Downloads/MySQL-5.6/MySQL-server-5.6.47-1.el6.x86_64.rpm
wget https://cdn.mysql.com//Downloads/MySQL-5.6/MySQL-client-5.6.47-1.el7.x86_64.rpm
wget https://cdn.mysql.com//Downloads/MySQL-5.6/ MySQL-devel-5.6.47-1.el7.x86_64.rpm

2.2 先下载到本地磁盘。再上传到云服务器

rz -y
如果rz -y 不弹窗,就需要安装
yum install lrzsz -y

先建立一个mysql5.6文件夹,将mysql下载到该文件夹中,如下图
云服务器配置CentOS 7.6(二)--安装mySQL_第3张图片

3.在安装之前,检查一下有没有系统自带的mysql相关的rpm文件,若有卸载掉

  • 卸载rpm的命令rpm -e 或者rpm -e --nodeps

rpm -qa |grep -i mysql
rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64

防止系统已经安装了其他版本的mysql-libs包和mysql数据库文件导致不兼容。不执行这句,mysql可能无法启动

yum remove mysql-libs

检查一下有没有系统自带的mysql相关的rpm文件,发现有一个卸载掉
在这里插入图片描述
再次校验
云服务器配置CentOS 7.6(二)--安装mySQL_第4张图片

4.开始安装–安装命令

  • 安装命令如下
    若安装mysql警告: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    原因:这是由于yum安装了旧版本的GPG keys造成的
    解决办法:后面加上

–force --nodeps

rpm -ivh MySQL-client-5.6.47-1.el7.x86_64.rpm --force --nodeps
rpm -ivh MySQL-server-5.6.47-1.el6.x86_64.rpm --force --nodeps
rpm -ivh MySQL-devel-5.6.47-1.el7.x86_64.rpm --force --nodeps

若还是出现:解决办法 后面加上–nosignature

rpm -ivh MySQL-server-5.6.47-1.el6.x86_64.rpm --nosignature
rpm -ivh MySQL-client-5.6.47-1.el7.x86_64.rpm --nosignature
rpm -ivh MySQL-devel-5.6.47-1.el7.x86_64.rpm --nosignature

在这里插入图片描述
若出现以下错误
执行以下命令,安装perl依赖

yum install -y perl-Module-Install.noarch

云服务器配置CentOS 7.6(二)--安装mySQL_第5张图片
在这里插入图片描述
安装完server后的信息提示

[root@instance-6uz2q7zs home]# rpm -ivh MySQL-server-5.6.47-1.el6.x86_64.rpm --force --nosignature
Preparing...                          ################################# [100%]
Updating / installing...
   1:MySQL-server-5.6.47-1.el6        ################################# [100%]
warning: user mysql does not exist - using root
warning: group mysql does not exist - using root
warning: user mysql does not exist - using root
warning: group mysql does not exist - using root
2020-02-04 13:54:24 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-02-04 13:54:24 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2020-02-04 13:54:24 0 [Note] /usr/sbin/mysqld (mysqld 5.6.47) starting as process 15276 ...
2020-02-04 13:54:24 15276 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-02-04 13:54:24 15276 [Note] InnoDB: The InnoDB memory heap is disabled
2020-02-04 13:54:24 15276 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-02-04 13:54:24 15276 [Note] InnoDB: Memory barrier is not used
2020-02-04 13:54:24 15276 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-02-04 13:54:24 15276 [Note] InnoDB: Using Linux native AIO
2020-02-04 13:54:24 15276 [Note] InnoDB: Using CPU crc32 instructions
2020-02-04 13:54:24 15276 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-02-04 13:54:24 15276 [Note] InnoDB: Completed initialization of buffer pool
2020-02-04 13:54:24 15276 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2020-02-04 13:54:24 15276 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2020-02-04 13:54:24 15276 [Note] InnoDB: Database physically writes the file full: wait...
2020-02-04 13:54:24 15276 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2020-02-04 13:54:25 15276 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2020-02-04 13:54:25 15276 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2020-02-04 13:54:25 15276 [Warning] InnoDB: New log files created, LSN=45781
2020-02-04 13:54:25 15276 [Note] InnoDB: Doublewrite buffer not found: creating new
2020-02-04 13:54:25 15276 [Note] InnoDB: Doublewrite buffer created
2020-02-04 13:54:25 15276 [Note] InnoDB: 128 rollback segment(s) are active.
2020-02-04 13:54:25 15276 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-02-04 13:54:25 15276 [Note] InnoDB: Foreign key constraint system tables created
2020-02-04 13:54:25 15276 [Note] InnoDB: Creating tablespace and datafile system tables.
2020-02-04 13:54:25 15276 [Note] InnoDB: Tablespace and datafile system tables created.
2020-02-04 13:54:25 15276 [Note] InnoDB: Waiting for purge to start
2020-02-04 13:54:25 15276 [Note] InnoDB: 5.6.47 started; log sequence number 0
2020-02-04 13:54:25 15276 [Note] RSA private key file not found: /var/lib/mysql//private_key.pem. Some authentication plugins will not work.
2020-02-04 13:54:25 15276 [Note] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work.
A random root password has been set. You will find it in '/root/.mysql_secret'.
2020-02-04 13:54:25 15276 [Note] Binlog end
2020-02-04 13:54:25 15276 [Note] InnoDB: FTS optimize thread exiting.
2020-02-04 13:54:25 15276 [Note] InnoDB: Starting shutdown...
2020-02-04 13:54:27 15276 [Note] InnoDB: Shutdown completed; log sequence number 1625977


2020-02-04 13:54:27 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-02-04 13:54:27 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2020-02-04 13:54:27 0 [Note] /usr/sbin/mysqld (mysqld 5.6.47) starting as process 15303 ...
2020-02-04 13:54:27 15303 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-02-04 13:54:27 15303 [Note] InnoDB: The InnoDB memory heap is disabled
2020-02-04 13:54:27 15303 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-02-04 13:54:27 15303 [Note] InnoDB: Memory barrier is not used
2020-02-04 13:54:27 15303 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-02-04 13:54:27 15303 [Note] InnoDB: Using Linux native AIO
2020-02-04 13:54:27 15303 [Note] InnoDB: Using CPU crc32 instructions
2020-02-04 13:54:27 15303 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-02-04 13:54:27 15303 [Note] InnoDB: Completed initialization of buffer pool
2020-02-04 13:54:27 15303 [Note] InnoDB: Highest supported file format is Barracuda.
2020-02-04 13:54:27 15303 [Note] InnoDB: 128 rollback segment(s) are active.
2020-02-04 13:54:27 15303 [Note] InnoDB: Waiting for purge to start
2020-02-04 13:54:27 15303 [Note] InnoDB: 5.6.47 started; log sequence number 1625977
2020-02-04 13:54:27 15303 [Note] RSA private key file not found: /var/lib/mysql//private_key.pem. Some authentication plugins will not work.
2020-02-04 13:54:27 15303 [Note] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work.
2020-02-04 13:54:27 15303 [Note] Binlog end
2020-02-04 13:54:27 15303 [Note] InnoDB: FTS optimize thread exiting.
2020-02-04 13:54:27 15303 [Note] InnoDB: Starting shutdown...
2020-02-04 13:54:29 15303 [Note] InnoDB: Shutdown completed; log sequence number 1625987




A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.

You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.

Also, the account for the anonymous user has been removed.

In addition, you can run:

  /usr/bin/mysql_secure_installation

which will also give you the option of removing the test database.
This is strongly recommended for production servers.

See the manual for more instructions.

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/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

在这里插入图片描述
在这里插入图片描述

5.开启mysql服务并配置

5.1 开启mysql服务和停止mysql服务

service mysql start
service mysql stop

如下图
云服务器配置CentOS 7.6(二)--安装mySQL_第6张图片
云服务器配置CentOS 7.6(二)--安装mySQL_第7张图片
我们可以查看进程中有没有mysql

ps -ef | grep mysql

在这里插入图片描述
很明显mysql已经成功启动了 我们接着再来看一下3306端口是否起了

lsof -i:3306

在这里插入图片描述
综上mysql服务启动成功.

6.设置自定义密码

我们使用这种方式 系统会自动给我们设置一个初始密码 我们来查看一下这个密码是什么

cat /root/.mysql_secret

可以看到初始密码是 2rw4z_UO_dMH0XZA
在这里插入图片描述
接下来修改初始密码。先进入mysql数据库

mysql -uroot -p2rw4z_UO_dMH0XZA

中途出现如下状况:网上查找的方法试了试依然不起作用。
此时我用的是百度云服务器CentOS / 6.8 x86_64 (64bit)系统
在这里插入图片描述
问题没解决,去升级了百度云服务器的版本,重装了操作系统,重新安装mysql

云服务器配置CentOS 7.6(二)--安装mySQL_第8张图片
接下来我们来设置我们想要的密码 我这里设置个简单的密码:123456

set PASSWORD=PASSWORD('123456');

在这里插入图片描述
设置成功。接下来我们用自己设置的密码登录

mysql -uroot -p123456

云服务器配置CentOS 7.6(二)--安装mySQL_第9张图片

7开启远程服务

grant all privileges on *.* to 'root' @'%' identified by '123456';
flush privileges;

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
本地连接服务器上的mysql成功
在这里插入图片描述
至此mysql安装及配置完成

8. MySQL的默认安装位置

8.1修改配置文件位置

[root@localhost rpm]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf

1 /var/lib/mysql/ #数据库目录
2 /usr/share/mysql #配置文件目录
3 /usr/bin #相关命令目录
4 /etc/init.d/mysql #启动脚本

8.2 数据库目录

-rw-rw---- 1 mysql mysql       56 Feb  2 10:14 auto.cnf
-rw-rw---- 1 mysql mysql 12582912 Feb  2 10:22 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Feb  2 10:22 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Feb  2 10:11 ib_logfile1		
-rw-rw---- 1 mysql mysql        5 Feb  2 10:22 instance-6uz2q7zs.pid
drwx--x--x 2 mysql mysql     4096 Feb  2 10:11 mysql
srwxrwxrwx 1 mysql mysql        0 Feb  2 10:22 mysql.sock
drwx------ 2 mysql mysql     4096 Feb  2 10:11 performance_schema
-rw-r--r-- 1 root  root       111 Feb  2 10:11 RPM_UPGRADE_HISTORY
-rw-r--r-- 1 mysql mysql      111 Feb  2 10:11 RPM_UPGRADE_MARKER-LAST
drwxr-xr-x 2 mysql mysql     4096 Feb  2 10:11 test
drwx------ 2 mysql mysql     4096 Feb  2 12:02 zxhzn

8.3 配置文件目录/usr/share/mysql

my-default.cnf

-rwxr-xr-x 1 root root   1153 Nov 27 02:18 binary-configure
drwxr-xr-x 2 root root   4096 Feb  2 10:11 bulgarian
drwxr-xr-x 2 root root   4096 Feb  2 10:11 charsets
drwxr-xr-x 2 root root   4096 Feb  2 10:11 czech
drwxr-xr-x 2 root root   4096 Feb  2 10:11 danish
-rwxr-xr-x 1 root root  25575 Nov 27 00:53 dictionary.txt
drwxr-xr-x 2 root root   4096 Feb  2 10:11 dutch
drwxr-xr-x 2 root root   4096 Feb  2 10:11 english
-rwxr-xr-x 1 root root 506879 Nov 27 00:53 errmsg-utf8.txt
drwxr-xr-x 2 root root   4096 Feb  2 10:11 estonian
-rwxr-xr-x 1 root root 850129 Nov 27 01:03 fill_help_tables.sql
drwxr-xr-x 2 root root   4096 Feb  2 10:11 french
drwxr-xr-x 2 root root   4096 Feb  2 10:11 german
drwxr-xr-x 2 root root   4096 Feb  2 10:11 greek
drwxr-xr-x 2 root root   4096 Feb  2 10:11 hungarian
-rwxr-xr-x 1 root root   3963 Nov 27 00:53 innodb_memcached_config.sql
drwxr-xr-x 2 root root   4096 Feb  2 10:11 italian
drwxr-xr-x 2 root root   4096 Feb  2 10:11 japanese
drwxr-xr-x 2 root root   4096 Feb  2 10:11 korean
-rwxr-xr-x 1 root root    773 Nov 27 00:53 magic
-rwxr-xr-x 1 root root   1126 Nov 27 02:18 my-default.cnf
-rwxr-xr-x 1 root root   1061 Nov 27 02:18 mysqld_multi.server
-rwxr-xr-x 1 root root    844 Nov 27 02:18 mysql-log-rotate
-rwxr-xr-x 1 root root   2121 Nov 27 00:53 mysql_security_commands.sql
-rwxr-xr-x 1 root root  10500 Nov 27 02:18 mysql.server
-rwxr-xr-x 1 root root   3972 Nov 27 00:53 mysql_system_tables_data.sql
-rwxr-xr-x 1 root root  93667 Nov 27 00:53 mysql_system_tables.sql
-rwxr-xr-x 1 root root  10834 Nov 27 00:53 mysql_test_data_timezone.sql
drwxr-xr-x 2 root root   4096 Feb  2 10:11 norwegian
drwxr-xr-x 2 root root   4096 Feb  2 10:11 norwegian-ny
drwxr-xr-x 2 root root   4096 Feb  2 10:11 polish
drwxr-xr-x 2 root root   4096 Feb  2 10:11 portuguese
drwxr-xr-x 2 root root   4096 Feb  2 10:11 romanian
drwxr-xr-x 2 root root   4096 Feb  2 10:11 russian
drwxr-xr-x 3 root root   4096 Feb  2 10:11 SELinux
drwxr-xr-x 2 root root   4096 Feb  2 10:11 serbian
drwxr-xr-x 2 root root   4096 Feb  2 10:11 slovak
drwxr-xr-x 2 root root   4096 Feb  2 10:11 spanish
drwxr-xr-x 2 root root   4096 Feb  2 10:11 swedish
drwxr-xr-x 2 root root   4096 Feb  2 10:11 ukrainian

9 修改字符集和数据存储路径

cd到【/etc】目录下,编辑 my.cnf文件

cp /usr/share/mysql/my-default.cnf /etc/my.cnf
vim my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]  
password        = 123456  
port            = 3306  
default-character-set=utf8  
[mysqld]  
port            = 3306  
character_set_server=utf8  
character_set_client=utf8  
collation-server=utf8_general_ci  
#(注意linux下mysql安装完后是默认:表名区分大小写,列名不区分大小写; 0:区分大小写,1:不区分大小写)  
lower_case_table_names=1  
##(设置最大连接数,默认为 151,MySQL服务器允许的最大连接数16384; )  
max_connections=1000  
#[mysql]  
#default-character-set = utf8

10.问题说明

若是远程连接不成功
1.看看服务器上有没有开启3306端口
2.关掉防火墙
设置防火墙开放3306端口 外部navicat即可访问了

/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
/etc/rc.d/init.d/iptables save

在这里插入图片描述
云服务器配置CentOS 7.6(二)--安装mySQL_第10张图片
用百度云服务器CentOS / 7.6 x86_64 (64bit)系统 安装Mysql5.6.47

中途出现其它状况可以卸载从新安装
可以参考其它博客
原文链接https://blog.csdn.net/typa01_kk/article/details/49059729

你可能感兴趣的:(Linux版云服务器)