阿里云ECS服务器安装Mysql5.7.28 详细版

文章目录

  • Mysql的三种安装方式
  • 详细步骤
    • 1. 解压,修改权限
    • 2.初始化mysql
      • 2.1配置默认配置my.cnf
      • 2.2进行初始化
      • 2.3配置环境变量
    • 3. 启动mysql(两种方式)
      • 默认方式启动
      • 服务的方式启动
    • 4. 登陆mysql
    • 5. 远程登陆mysql
  • debug详解
    • error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
    • error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
    • mysqld_safe mysqld from pid file /home/work/mysql-5.7.28/data/mysqld.pid ended
    • './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
    • Failed to start mysqld.service: Unit not found.
    • You must reset your password using ALTER USER statement before executing this statement
    • Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
  • 经验

Mysql的三种安装方式

  1. RPM方式安装
  2. 二进制安装(推介安装)
  3. 源码安装:需要熟悉编译命令等等
    注:
    RPM安装简单但无脑,并不能指定安装目录,也不能详细了解mysql的相关参数和安装细节,所以不推介使用
    源码安装复杂,需要了解复杂编译命令,故不选择

详细步骤

1. 解压,修改权限

drwxrwxr-x 7  500  500 4096 Jul  4 20:15 jdk1.8.0_221
drwxr-xr-x 9 root root 4096 Dec 12 00:20 mysql-5.7.28-linux-glibc2.12-i686
drwxr-xr-x 8 root root 4096 Dec  6 15:45 zookeeper-3.5.6
[root@WeekLog work]# mv mysql-5.7.28-linux-glibc2.12-i686/ mysql-5.7.28
[root@WeekLog work]# ln -s mysql-5.7.28/ mysql
[root@WeekLog work]# ll
total 12
drwxrwxr-x 7  500  500 4096 Jul  4 20:15 jdk1.8.0_221
lrwxrwxrwx 1 root root   13 Dec 12 00:20 mysql -> mysql-5.7.28/
drwxr-xr-x 9 root root 4096 Dec 12 00:20 mysql-5.7.28
drwxr-xr-x 8 root root 4096 Dec  6 15:45 zookeeper-3.5.6
[root@WeekLog work]# 
[root@WeekLog work]# chown -R mysql:mysql mysql
[root@WeekLog work]# ll
total 12
drwxrwxr-x 7   500   500 4096 Jul  4 20:15 jdk1.8.0_221
lrwxrwxrwx 1 mysql mysql   13 Dec 12 00:20 mysql -> mysql-5.7.28/
drwxr-xr-x 9 mysql mysql 4096 Dec 12 00:20 mysql-5.7.28
drwxr-xr-x 8 root  root  4096 Dec  6 15:45 zookeeper-3.5.6

2.初始化mysql

2.1配置默认配置my.cnf

[mysql]
#设置客户端默认字符集
default-character-set=utf8
[mysqld]
#设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=//home/work/mysql-5.7.28
# 设置mysql数据库的数据的存放目录
datadir=//home/work/mysql-5.7.28/data
#免密登陆
#skip-grant-tables
#设置日志文件夹
log-error=/home/work/mysql-5.7.28/data/mysqld.log
pid-file=/home/work/mysql-5.7.28/data/mysqld.pid
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
#设置密码过期时间-永不过期
default_password_lifetime=0

2.2进行初始化

## 进行初始化
[root@WeekLog mysql]# mysqld --initialize  --user=mysql --basedir /home/work/mysql --datadir=/home/work/mysql/data/
2019-12-12T02:32:09.890283Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-12-12T02:32:10.928332Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-12-12T02:32:11.055194Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-12-12T02:32:11.116952Z 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: 99969fa1-1c87-11ea-99fb-00163e12d173.
2019-12-12T02:32:11.118550Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-12-12T02:32:13.539037Z 0 [Warning] CA certificate ca.pem is self signed.
2019-12-12T02:32:13.706642Z 1 [Note] A temporary password is generated for root@localhost: ikmuwB_gd6e:

2.3配置环境变量

vim /etc/profile
source /etc/profile

注:如果cosole没有打印出来,启动日志中存在此日志

3. 启动mysql(两种方式)

默认方式启动

[root@WeekLog mysql]# mysqld_safe --user=mysql &
[root@WeekLog mysql]# 2019-12-12T02:34:05.874294Z mysqld_safe Logging to '/home/work/mysql-5.7.28/data/mysqld.log'.
2019-12-12T02:34:05.896016Z mysqld_safe Starting mysqld daemon with databases from //home/work/mysql-5.7.28/data

[root@WeekLog mysql]# 

服务的方式启动

## 1. 添加mysql服务到服务器
cp support-files/mysql.server /etc/init.d/mysqld
## 2. 修改配置
vim /etc/init.d/mysqld
basedir=/home/work/mysql
datadir=/home/work/mysql/mysql_data
## 3. 启动mysql服务
[root@WeekLog mysql-5.7.28]# service mysqld status
MySQL running (29645)                                      [  OK  ]
[root@WeekLog mysql-5.7.28]# 
## 4. 配置开机自启动
chkconfig  --add mysql --添加mysql到自启动
chmod +x /etc/init.d/mysql 为其添加可执行权限

4. 登陆mysql

[root@WeekLog ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.28 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> 

5. 远程登陆mysql

mysql> grant all privileges on *.* to root@"%" identified by "7250831";
Query OK, 0 rows affected, 1 warning (0.01 sec)

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

mysql> 

debug详解

评:真的是一步一bug,阿里云还需要很大改进空间!!!

error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

## 执行 mysqld --initialize 初始化时报错
## 解决:yum -y install libaio*  还不行
##            查找此lib依赖的包:yum provides libstdc++.so.6
##            yum install bao 
## 结果:彻底解决

error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

## yum install numactl 网上找的方法怎么都不起作用!!
## yum search numactl 搜索所有numactl相关的依赖
## yum install *** 安装所有搜索的包
## 结果:彻底解决

mysqld_safe mysqld from pid file /home/work/mysql-5.7.28/data/mysqld.pid ended

[1]+  Done                    mysqld_safe --user=mysql
现象:怎么都启动不成功
解决:查找err.log日志发现由于mysql.sock文件被锁定引起
[root@WeekLog mysql-5.7.28]# cd /tmp/
[root@WeekLog tmp]# ll
total 12
srwxr-xr-x 1 root  root     0 Nov 19 12:50 Aegis-
drwxr-xr-x 2 root  root  4096 Dec 11 18:24 hsperfdata_root
lrwxrwxrwx 1 root  root    25 Dec 11 21:20 mysql.sock -> /var/lib/mysql/mysql.sock————红色闪烁
-rw------- 1 mysql mysql    6 Dec 12 10:19 mysql.sock.lock————mysql.sock被错误锁定
drwx------ 3 root  root  4096 Sep 28 15:07 systemd-private-c90679b6e151448e8b707e72ce91995b-chronyd.service-or1zhU
[root@WeekLog tmp]# rm -rf mysql.sock.lock 
[root@WeekLog tmp]# rm -rf mysql.sock
结果:彻底解决

‘./ibtmp1’ size to 12 MB. Physically writing the file full; Please wait …

## 删除:ibdata1、ib_logfile0、ib_logfile1 后启动正常
## 配置的日志文件没有日志打印:配置log-error到真实目录得文件夹下

Failed to start mysqld.service: Unit not found.

## 没有配置mysql服务

You must reset your password using ALTER USER statement before executing this statement

mysql> use mysql;
ERROR 1820 (HY000): .
MySQL版本5.7.6版本以前用户可以使用如下命令:

mysql> SET PASSWORD = PASSWORD('Xiaoming250'); 
MySQL版本5.7.6版本开始的用户可以使用如下命令:

mysql> alter user user() identified by '7250831';  重置密码

Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

## 1. my..cnf不要配置sock
## 2. 配置后要设置软连接(参考internet)

经验

1. 查看错误日志:tail适合查看动态日志   cat适合查看静态日志
2. mysqld_safe指定的--datadir参数会覆盖my.cnf中的配置

你可能感兴趣的:(项目经验,mysql,阿里云,ecs,mysql5.7.28)