Centos 7 二进制安装配置 Mysql数据库

一、环境描述

系统:Centos7.8.2003
IP地址:192.168.6.101
Mysql版本:5.7.31
下载地址:https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
Centos7系统优化:https://blog.youkuaiyun.com/xjjj064/article/details/106219716
防火墙、selinux:防火墙关闭或放行数据库端口,selinux设置为disabled

二、准备工作

①、安装依赖、下载二进制包

[root@server1 ~]# yum install -y ncurses-devel libaio-devel autoconf
[root@server1 ~]# cd /usr/local/src/
[root@server1 src]# wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz

②、创建运行mysql的用户

[root@server1 ~]# useradd mysql -s /sbin/nologin -M
[root@server1 src]# mkdir /usr/local/mysql
#解压mysql 到 /usr/local/mysql 目录下
[root@server1 src]# tar -zxvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/mysql
#设置环境变量
[root@server1 mysql]# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@server1 mysql]# source /etc/profile

③、创建数据库目录,并修改属主和数组

#创建数据存储路径
[root@server1 mysql]# mkdir -p /data/mysql
#binlog存放路径
[root@server1 mysql]# mkdir -p /data/log/binlog
[root@server1 mysql]# touch /data/log/mysql3301_log.err
#修改属主和数组
[root@server1 mysql]# chown -R mysql:mysql /data/
[root@server1 mysql]# ls -l /data/
total 0
drwxr-xr-x 3 mysql mysql 20 Dec 28 10:27 log
drwxr-xr-x 2 mysql mysql  6 Dec 28 10:26 mysql

④、创建mysql.cnf文件

[mysqld]
server_id=11
max_connections=5000
port=3301
#此配置修改了mysql默认3306端口
user=mysql
character_set_server=utf8
innodb_file_per_table=1
expire_logs_days=15
explicit_defaults_for_timestamp=true

log_error=/data/log/mysql3301_log.err
#socket=/data/mysql/mysql3301.socket
innodb_buffer_pool_size=6000MB
innodb_flush_log_at_trx_commit=1

log_bin=/data/log/binlog/binlog
sync_binlog=1
binlog_format=row
#binlog记录的三种方式:https://www.cnblogs.com/barrywxx/p/11544473.html#top
#innodb_support_xa=on

[mysqld_safe]
basedir=/usr/local/mysql
datadir=/data/mysql
pid-file=/data/log/mysql3301.pid

⑤、初始化数据库

/usr/local/mysql
[root@server1 mysql]# ./bin/mysqld --initialize-insecure --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql
2020-12-28T02:34:02.719463Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-12-28T02:34:03.506722Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-12-28T02:34:03.614345Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-12-28T02:34:03.681819Z 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: 267b27d0-48b5-11eb-92ec-000c290f457f.
2020-12-28T02:34:03.683858Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-12-28T02:34:05.060130Z 0 [Warning] CA certificate ca.pem is self signed.
2020-12-28T02:34:05.523310Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

注:以上警告需要修改mysql.cnf 添加以下配置

[mysqld]
explicit_defaults_for_timestamp=true

⑥、启动mysql

[root@server1 mysql]# ./bin/mysqld_safe --defaults-file=/etc/mysql.cnf &
[1] 12685
[root@server1 mysql]# 2020-12-28T02:45:34.443621Z mysqld_safe Logging to '/data/log/mysql3301_log.err'.
2020-12-28T02:45:34.520853Z mysqld_safe Starting mysqld daemon with databases from /data/mysql

[root@server1 mysql]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      959/sshd            
tcp        0      0 0.0.0.0:35672           0.0.0.0:*               LISTEN      967/haproxy         
tcp        0      0 0.0.0.0:55672           0.0.0.0:*               LISTEN      967/haproxy         
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1134/master         
tcp        0      0 0.0.0.0:514             0.0.0.0:*               LISTEN      962/rsyslogd        
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      967/haproxy         
tcp6       0      0 :::22                   :::*                    LISTEN      959/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1134/master         
tcp6       0      0 :::514                  :::*                    LISTEN      962/rsyslogd        
tcp6       0      0 :::3301                 :::*                    LISTEN      12952/mysqld

⑦、初始化mysql安全设置

[root@server1 mysql]# ./bin/mysql_secure_installation 

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: n
Please set the password for root here.

New password: 

Re-enter new password: 
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.

All done! 

测试登录

[root@server1 mysql]# ./bin/mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.31-log MySQL Community Server (GPL)

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.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

⑧、授予root远程登录权限

mysql> GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY '*******';
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

mysql> 

在这里插入图片描述
⑨、设置开机启动mysql

[root@server1 mysql]# chmod u+x /etc/rc.d/rc.local
[root@server1 mysql]# vim /etc/rc.local
[root@server1 mysql]# cat /etc/rc.local 
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/mysql.cnf &

重启测试

[root@server1 mysql]# reboot
Connection closing...Socket close.

Connection closed by foreign host.

Disconnected from remote host(192.168.6.101) at 10:57:00.

Type `help' to learn how to use Xshell prompt.
[D:\~]$ 

Connecting to 192.168.6.101:22...
Connection established.
To escape to local shell, press Ctrl+Alt+].

Last login: Mon Dec 28 10:12:03 2020 from 192.168.7.119
[root@server1 ~]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      999/haproxy         
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      950/sshd            
tcp        0      0 0.0.0.0:35672           0.0.0.0:*               LISTEN      999/haproxy         
tcp        0      0 0.0.0.0:55672           0.0.0.0:*               LISTEN      999/haproxy         
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1405/master         
tcp        0      0 0.0.0.0:514             0.0.0.0:*               LISTEN      953/rsyslogd        
tcp6       0      0 :::22                   :::*                    LISTEN      950/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1405/master         
tcp6       0      0 :::514                  :::*                    LISTEN      953/rsyslogd        
tcp6       0      0 :::3301                 :::*                    LISTEN      1365/mysqld

Centos8 安装mysql启动报错

①、报错信息:

[root@localhost mysql]# ./bin/mysql -uroot -p
./bin/mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

解决办法:

yum -y install libncurses*

参考:https://www.cnblogs.com/gshelldon/p/13387636.html

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值