百木园-与人分享,
就是让自己快乐。

Centos7环境使用Mysql离线安装包安装Mysql5.7

服务器环境:centos7 x64

需要安装:mysql5.7+

一、卸载CentOS7系统自带mariadb

# 查看系统自带的Mariadb
[root@CDH-141 ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64

# 卸载系统自带的Mariadb(rpm -e --nodeps) 
[root@CDH-141 ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64

# 删除etc目录下的my.cnf 
[root@CDH-141 ~]# rm /etc/my.cnf

二、检查mysql是否存在

# 检查mysql是否存在
[root@CDH-141 ~]# rpm -qa | grep mysql

三、查看用户和组是否存在

1)检查mysql组合用户是否存在

# 检查mysql组和用户是否存在,如无则创建
[root@CDH-141 ~]# cat /etc/group | grep mysql
[root@CDH-141 ~]# cat /etc/passwd | grep mysql

2)若不存在,则创建mysql组和用户

[root@CDH-141 ~]# groupadd mysql # 创建mysql用户组
[root@CDH-141 ~]# useradd -g mysql mysql   # 创建一个用户名为mysql的用户,并加入mysql用户组
[root@CDH-141 ~]# passwd mysql   # 制定password 为111111  (用户mysql的密码)
Changing password for user mysql.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.

四、下载mysql离线安装包tar文件

官网下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

版本选择,可以选择以下两种方式:

1)使用Red Hat Enterprise Linux

   Select Version:5.7.35
   Select Operating System:Red Hat Enterprise Linux / Oracle Linux
   Select OS Version:Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit)
   列表中下载:
   Compressed TAR Archive:(mysql-5.7.35-el7-x86_64.tar.gz)

2)使用Linux - Generic

2)使用Linux - Generic
  Select Version:5.7.35
  Select Operating System:Linux - Generic
  Select OS Version:Linux - Generic (glibc 2.12) (x86, 64-bit)
  列表中下载:
  Compressed TAR Archive:(mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz)【本文中使用的是这个版本】

2)百度网盘

链接:https://pan.baidu.com/s/1-FnDtfsq-gFOcewVXYSGAw 
提取码:2zhz 

注意:上边三种方式找mysql离线安装包的方式都可以。

五、上传第四步下载的mysql TAR包

# 进入/usr/local/文件夹(此目录作为安装目录,给根据自己目录安排可自行更换目录,后续目录保持一致即可)
[root@CDH-141 ~]# cd /usr/local/

# 上传mysql TAR包
[root@CDH-141 local]# rz

# 解压mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
[root@CDH-141 local]# tar -zxvf mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
# 进入/usr/local下,修改为mysql
[root@CDH-141 local]# mv mysql-5.7.35-linux-glibc2.12-x86_64  mysql
[root@CDH-141 local]# ls
bin  etc  full-path-to-mysql-VERSION-OS  games  include  lib  lib64  libexec  mysql  mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz  sbin  share  src

六、更改所属的组和用户

# 更改所属的组和用户
[root@CDH-141 ~]# cd /usr/local/
[root@CDH-141 local]# chown -R mysql mysql/
[root@CDH-141 local]# chgrp -R mysql mysql/
[root@CDH-141 local]# cd mysql/
[root@CDH-141 mysql]# mkdir data
[root@CDH-141 mysql]# chown -R mysql:mysql data
备注:
chown -R mysql:mysql ./

chown [选项]... [所有者][:[组]] 文件...

  必要参数:

       -c 显示更改的部分的信息
    -f 忽略错误信息
    -h 修复符号链接
    -R 处理指定目录以及其子目录下的所有文件
    -v 显示详细的处理信息
    -deference 作用于符号链接的指向,而不是链接文件本身
  选择参数:
    --reference=<目录或文件> 把指定的目录/文件作为参考,把操作的文件/目录设置成参考文件/目录相同拥有者和群组
    --from=<当前用户:当前群组> 只有当前用户和群组跟指定的用户和群组相同时才进行改变
    --help 显示帮助信息
    --version 显示版本信息

七、在/etc下创建my.cnf文件

# 进入/usr/local/mysql文件夹下
[root@CDH-141 ~]# cd /usr/local/mysql

# 创建my.cnf文件
[root@CDH-141 mysql]# touch my.cnf

# 编辑my.cnf
[root@CDH-141 mysql]# vi my.conf

[mysql]
socket=/var/lib/mysql/mysql.sock
# set mysql client default chararter
default-character-set=utf8

[mysqld]
socket=/var/lib/mysql/mysql.sock
# set mysql server port  
port = 3323 #默认是3306
# set mysql install base dir
basedir=/usr/local/mysql
# set the data store dir
datadir=/usr/local/mysql/data
# set the number of allow max connnection
max_connections=200
# set server charactre default encoding
character-set-server=utf8
# the storage engine
default-storage-engine=INNODB
#忽略数据库表名的大小写
lower_case_table_names=1
#最大请求包
max_allowed_packet=16M
explicit_defaults_for_timestamp=true
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

[mysql.server]
user=mysql #用户不是mysql时,更改此处
basedir=/usr/local/mysql

八、进入mysql文件夹,并安装mysql

# 进入mysql
[root@CDH-141 local]# cd /usr/local/mysql

# 安装mysql
[root@CDH-141 mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
或者
cd bin
./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2019-03-08 18:11:07 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2019-03-08 18:11:24 [WARNING] The bootstrap log isn\'t empty:
2019-03-08 18:11:24 [WARNING] 2019-03-08T10:11:07.208602Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead

设置文件及目录权限:

[root@CDH-141 mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@CDH-141 mysql]# chown 777 my.cnf
[root@CDH-141 mysql]# chmod +x /etc/init.d/mysqld
[root@CDH-141 mysql]# mkdir data
[root@CDH-141 mysql]# chown -R mysql:mysql data

九、启动mysql

# 启动mysql
[root@CDH-141 mysql]# /etc/init.d/mysqld start/restart/stop/status
或者
[root@CDH-141 mysql]# service mysqld start/stop/restart/status

十、设置开机启动

#设置开机启动
[root@CDH-141 mysql]# chkconfig --level 35 mysqld on
[root@CDH-141 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
[root@CDH-141 mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@CDH-141 mysql]# chkconfig --add mysqld
[root@CDH-141 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
[root@CDH-141 mysql]# service mysqld status
MySQL running (26122)[  OK  ]
[root@CDH-141 mysql]# 

十一、修改配置文件(配置环境变量)

# 进入/etc/profile文件夹
[root@CDH-141 mysql]# vim /etc/profile

修改/etc/profile,在最后添加如下内容
export PATH=$PATH:/usr/local/mysql/bin

# 使文件生效
[root@CDH-141 mysql]# source /etc/profile

十二、获得mysql初始密码

 1)获得mysql初始密码

[root@CDH-141 mysql]#  cat /root/.mysql_secret  
# Password set for user \'root@localhost\' at 2019-03-08 17:40:42 poc3u0mO_luv

2)修改密码

[root@CDH-141 mysql]# mysql -uroot -p

Enter password: #此处填写上边获取到的初始密码 ‘poc3u0mO_luv’

mysql>  set PASSWORD = PASSWORD(\'123456\');
或者
mysql> ALTER USER \'root\'@\'localhost\' IDENTIFIED BY \'MyNewPass4!\'; 
或者(本人一般使用下面的修改密码的方式)
mysql> set password for \'root\'@\'localhost\'=password(\'MyNewPass4!\'); 

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

mysql> exit


备注:

修改密码时报错:
Can\'t connect to local MySQL server through socket \'/tmp/mysql.sock\'
上述提示可能在启动mysql时遇到,即在/tmp/mysql.sock位置找不到所需要的mysql.sock文件,主要是由于my.cnf文件里对mysql.sock的位置设定导致。

mysql.sock默认的是在/var/lib/mysql, 如果发现确实是在该目录下,可以在[mysqld]下面加入mysql.sock的path

vi /etc/my.cnf(my.cnf也可能在其他路径下)

[mysqld]

port = 3306

socket = /var/lib/mysql/mysql.sock

但是要保证使用mysql的用户具有对该目录的写权限,否则这样的改动由于权限限制仍然会报错。

所以为了避免权限问题也可以使用软链接为/var/lib/mysql/mysql.sock创建一个到/tmp/mysql.sock的联接

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

由于/tmp/文件夹默认对other有w权限,这样就可以避免权限问题。

此外,如果发现mysql.sock不在默认的/var/lib/mysql位置,一种解决方法是使用find命令搜索mysql.sock的位置,然后按前面两种解决方案挑一种做即可。

3)验证新密码是否登录成功:

[root@CDH-141 mysql]# mysql -uroot -p
Enter password: #此处输入新密码‘123456’
Welcome to the MySQL monitor.  Commands end with ; or \\g.
Your MySQL connection id is 4
Server version: 5.7.25 MySQL Community Server (GPL)

mysql> show tables;
ERROR 1046 (3D000): No database selected
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

十三、添加远程访问权限

# 添加远程访问权限
mysql> use mysql

# 修改root用户可以远程登录:
mysql> update user set host=\'%\' where user=\'root\';
或者
mysql> GRANT ALL PRIVILEGES ON *.* TO \'root\'@\'%\' IDENTIFIED BY \'root用户密码\' WITH GRANT OPTION;

mysql> select host,user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| %         | root          |
| localhost | mysql.session |
| localhost | mysql.sys     |
+-----------+---------------+
3 rows in set (0.00 sec)

十四、重启mysql生效

[root@CDH-141 mysql]# service mysqld restart
备注:
    由于安装在/usr/local下面的mysql,因此可以在热河文件夹启动mysql
    若安装在别的文件夹,请执行以下命令:

   # 为了在任何目录下可以登录mysql
 
     ln -s /你的mysql路径/mysql /usr/local/mysql

十五、安装过程(仅供参考)

[root@localhost ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost ~]# rm /etc/my.cnf
rm: cannot remove ‘/etc/my.cnf’: No such file or directory
[root@localhost ~]# rpm -qa | grep mysql
[root@localhost ~]# cat /etc/group | grep mysql
[root@localhost ~]# cat /etc/passwd | grep mysql
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -g mysql mysql
[root@localhost ~]# passwd mysql
Changing password for user mysql.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
Sorry, passwords do not match.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# cd /home/
[root@localhost home]# ll
total 4
drwxr-xr-x.  3 root     root       18 Apr 28 20:35 install
drwx------.  3 mysql    mysql      78 Aug  7 07:02 mysql
drwx------. 15 panhusun panhusun 4096 Aug  7 06:52 panhusun
drwxr-xr-x.  2 root     root        6 Apr 21 01:12 server
drwxr-xr-x.  4 root     root      214 May 11 02:43 tar
[root@localhost home]# cd tar/
[root@localhost tar]# ll
total 559012
-rwxr-xr-x.  1 root root      11156 Apr 20 03:54 get_helm.sh
-rw-r--r--.  1 root root   62468096 Apr 20 23:55 k3s
-rw-r--r--.  1 root root  503815168 Apr 20 04:28 k3s-airgap-images-amd64.tar
-rw-r--r--.  1 root root      15152 Oct  8  2021 k3s-selinux-0.4-1.el7.noarch.rpm
drwxr-xr-x. 11 root root       4096 May 11 02:49 libressl-3.5.2
-rw-r--r--.  1 root root    4039407 May 11 02:43 libressl-3.5.2.tar.gz
drwxr-xr-x. 14  501 games      4096 May 11 01:29 zlib-1.2.12
-rw-r--r--.  1 root root    2060528 May 11 01:58 zlib-1.2.12Upgrade.tar.gz
[root@localhost tar]# pwd
/home/tar
[root@localhost tar]# ^C
[root@localhost tar]# ll
total 1209952
-rwxr-xr-x.  1 root root      11156 Apr 20 03:54 get_helm.sh
-rw-r--r--.  1 root root   62468096 Apr 20 23:55 k3s
-rw-r--r--.  1 root root  503815168 Apr 20 04:28 k3s-airgap-images-amd64.tar
-rw-r--r--.  1 root root      15152 Oct  8  2021 k3s-selinux-0.4-1.el7.noarch.rpm
drwxr-xr-x. 11 root root       4096 May 11 02:49 libressl-3.5.2
-rw-r--r--.  1 root root    4039407 May 11 02:43 libressl-3.5.2.tar.gz
-rw-r--r--.  1 root root  666559924 Aug  7 07:04 mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
drwxr-xr-x. 14  501 games      4096 May 11 01:29 zlib-1.2.12
-rw-r--r--.  1 root root    2060528 May 11 01:58 zlib-1.2.12Upgrade.tar.gz
[root@localhost tar]# cp mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz /usr/local/
[root@localhost tar]# cd /usr/local/
[root@localhost local]# ll
total 650940
drwxr-xr-x. 2 root root       122 Apr 21 00:03 bin
drwxr-xr-x. 2 root root         6 Apr 10  2018 etc
drwxr-xr-x. 2 root root         6 Apr 10  2018 games
drwxr-xr-x. 2 root root        35 May 11 02:00 include
drwxr-xr-x. 2 root root         6 Apr 10  2018 lib
drwxr-xr-x. 2 root root         6 Apr 10  2018 lib64
drwxr-xr-x. 2 root root         6 Apr 10  2018 libexec
-rw-r--r--. 1 root root 666559924 Aug  7 07:04 mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
drwxr-xr-x. 2 root root         6 Apr 10  2018 sbin
drwxr-xr-x. 5 root root        49 Feb 25 19:38 share
drwxr-xr-x. 2 root root         6 Apr 10  2018 src
[root@localhost local]# tar -zxvf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
mysql-5.7.36-linux-glibc2.12-x86_64/bin/myisam_ftdump
mysql-5.7.36-linux-glibc2.12-x86_64/bin/myisamchk
mysql-5.7.36-linux-glibc2.12-x86_64/bin/myisamlog
mysql-5.7.36-linux-glibc2.12-x86_64/bin/myisampack
mysql-5.7.36-linux-glibc2.12-x86_64/bin/mysql
mysql-5.7.36-linux-glibc2.12-x86_64/bin/mysql_client_test_embedded
mysql-5.7.36-linux-glibc2.12-x86_64/bin/mysql_config_editor
mysql-5.7.36-linux-glibc2.12-x86_64/bin/mysql_embedded
mysql-5.7.36-linux-glibc2.12-x86_64/bin/mysql_install_db
mysql-5.7.36-linux-glibc2.12-x86_64/bin/mysql_plugin
mysql-5.7.36-linux-glibc2.12-x86_64/bin/mysql_secure_installation
mysql-5.7.36-linux-glibc2.12-x86_64/bin/mysql_ssl_rsa_setup
mysql-5.7.36-linux-glibc2.12-x86_64/bin/mysql_tzinfo_to_sql
。。。。。。
[root@localhost local]# mv mysql-5.7.36-linux-glibc2.12-x86_64 mysql
[root@localhost local]# ll
total 650940
drwxr-xr-x. 2 root root       122 Apr 21 00:03 bin
drwxr-xr-x. 2 root root         6 Apr 10  2018 etc
drwxr-xr-x. 2 root root         6 Apr 10  2018 games
drwxr-xr-x. 2 root root        35 May 11 02:00 include
drwxr-xr-x. 2 root root         6 Apr 10  2018 lib
drwxr-xr-x. 2 root root         6 Apr 10  2018 lib64
drwxr-xr-x. 2 root root         6 Apr 10  2018 libexec
drwxr-xr-x. 9 root root       129 Aug  7 07:05 mysql
-rw-r--r--. 1 root root 666559924 Aug  7 07:04 mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
drwxr-xr-x. 2 root root         6 Apr 10  2018 sbin
drwxr-xr-x. 5 root root        49 Feb 25 19:38 share
drwxr-xr-x. 2 root root         6 Apr 10  2018 src
[root@localhost local]# rm -f mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
[root@localhost local]# ll
total 0
drwxr-xr-x. 2 root root 122 Apr 21 00:03 bin
drwxr-xr-x. 2 root root   6 Apr 10  2018 etc
drwxr-xr-x. 2 root root   6 Apr 10  2018 games
drwxr-xr-x. 2 root root  35 May 11 02:00 include
drwxr-xr-x. 2 root root   6 Apr 10  2018 lib
drwxr-xr-x. 2 root root   6 Apr 10  2018 lib64
drwxr-xr-x. 2 root root   6 Apr 10  2018 libexec
drwxr-xr-x. 9 root root 129 Aug  7 07:05 mysql
drwxr-xr-x. 2 root root   6 Apr 10  2018 sbin
drwxr-xr-x. 5 root root  49 Feb 25 19:38 share
drwxr-xr-x. 2 root root   6 Apr 10  2018 src
[root@localhost local]# chown -R mysql mysql/
[root@localhost local]# chgrp -R mysql mysql/
[root@localhost local]# cd mysql/
[root@localhost mysql]# mkdir data
[root@localhost mysql]# chown -R mysql:mysql data
[root@localhost mysql]# cd /etc/
[root@localhost etc]# ll
total 1420
drwxr-xr-x.  3 root root      101 Feb 25 19:43 abrt
-rw-r--r--.  1 root root       16 Feb 25 19:51 adjtime
-rw-r--r--.  1 root root     1529 Mar 31  2020 aliases
-rw-r--r--.  1 root root    12288 Feb 25 19:52 aliases.db
drwxr-xr-x.  3 root root       65 Feb 25 19:46 alsa
drwxr-xr-x.  2 root root     4096 Feb 25 19:51 alternatives
-rw-------.  1 root root      541 Aug  8  2019 anacrontab
-rw-r--r--.  1 root root       55 Aug  8  2019 asound.conf
-rw-r--r--.  1 root root        1 Oct 30  2018 at.deny
drwxr-x---.  3 root root       43 Feb 25 19:43 audisp
drwxr-x---.  3 root root       83 Feb 25 19:52 audit
-rw-r--r--.  1 root root    15137 Sep 30  2020 autofs.conf
-rw-------.  1 root root      232 Sep 30  2020 autofs_ldap_auth.conf
-rw-r--r--.  1 root root      795 Sep 30  2020 auto.master
drwxr-xr-x.  2 root root        6 Sep 30  2020 auto.master.d
-rw-r--r--.  1 root root      524 Sep 30  2020 auto.misc
-rwxr-xr-x.  1 root root     1260 Sep 30  2020 auto.net
-rwxr-xr-x.  1 root root      687 Sep 30  2020 auto.smb
drwxr-xr-x.  4 root root       71 Feb 25 19:46 avahi
。。。。。。
[root@localhost etc]# touch my.cnf
[root@localhost etc]# ll
total 1420
drwxr-xr-x.  3 root root      101 Feb 25 19:43 abrt
-rw-r--r--.  1 root root       16 Feb 25 19:51 adjtime
-rw-r--r--.  1 root root     1529 Mar 31  2020 aliases
-rw-r--r--.  1 root root    12288 Feb 25 19:52 aliases.db
drwxr-xr-x.  3 root root       65 Feb 25 19:46 alsa
drwxr-xr-x.  2 root root     4096 Feb 25 19:51 alternatives
-rw-------.  1 root root      541 Aug  8  2019 anacrontab
-rw-r--r--.  1 root root       55 Aug  8  2019 asound.conf
-rw-r--r--.  1 root root        1 Oct 30  2018 at.deny
drwxr-x---.  3 root root       43 Feb 25 19:43 audisp
drwxr-x---.  3 root root       83 Feb 25 19:52 audit
。。。。。。
[root@localhost etc]# pwd
/etc
[root@localhost etc]# cd /usr/local/mysql/
[root@localhost mysql]# ll
total 272
drwxr-xr-x.  2 mysql mysql   4096 Aug  7 07:05 bin
drwxr-xr-x.  2 mysql mysql      6 Aug  7 07:06 data
drwxr-xr-x.  2 mysql mysql     55 Aug  7 07:05 docs
drwxr-xr-x.  3 mysql mysql   4096 Aug  7 07:05 include
drwxr-xr-x.  5 mysql mysql    230 Aug  7 07:05 lib
-rw-r--r--.  1 mysql mysql 259199 Sep  6  2021 LICENSE
drwxr-xr-x.  4 mysql mysql     30 Aug  7 07:05 man
-rw-r--r--.  1 mysql mysql    566 Sep  6  2021 README
drwxr-xr-x. 28 mysql mysql   4096 Aug  7 07:05 share
drwxr-xr-x.  2 mysql mysql     90 Aug  7 07:05 support-files
[root@localhost mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --
2022-08-07 07:09:15 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2022-08-07 07:09:15 [ERROR]   The data directory needs to be specified.
[root@localhost mysql]# cd bin/
[root@localhost bin]# mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --
bash: mysql_install_db: command not found...
[root@localhost bin]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --
2022-08-07 07:09:40 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2022-08-07 07:09:40 [ERROR]   The data directory needs to be specified.
[root@localhost bin]# cd bi
-bash: cd: bi: No such file or directory
[root@localhost bin]# cd bin
-bash: cd: bin: No such file or directory
[root@localhost bin]# ll
total 1348160
-rwxr-xr-x. 1 mysql mysql   8147275 Sep  7  2021 innochecksum
-rwxr-xr-x. 1 mysql mysql    359769 Sep  7  2021 lz4_decompress
-rwxr-xr-x. 1 mysql mysql  10101581 Sep  7  2021 myisamchk
-rwxr-xr-x. 1 mysql mysql   9642658 Sep  7  2021 myisam_ftdump
-rwxr-xr-x. 1 mysql mysql   7539128 Sep  7  2021 myisamlog
-rwxr-xr-x. 1 mysql mysql   9769178 Sep  7  2021 myisampack
-rwxr-xr-x. 1 mysql mysql   7435495 Sep  7  2021 my_print_defaults
-rwxr-xr-x. 1 mysql mysql  10456480 Sep  7  2021 mysql
。。。。。。
[root@localhost bin]# ./mysqld --initialize --user=mysql
2022-08-07T14:10:55.428560Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-08-07T14:10:55.485143Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-08-07T14:10:55.549898Z 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: c0c72931-165a-11ed-b15d-000c290923cd.
2022-08-07T14:10:55.552919Z 0 [Warning] Gtid table is not ready to be used. Table \'mysql.gtid_executed\' cannot be opened.
2022-08-07T14:10:56.502231Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-08-07T14:10:56.502306Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-08-07T14:10:56.504364Z 0 [Warning] CA certificate ca.pem is self signed.
2022-08-07T14:10:56.740944Z 1 [Note] A temporary password is generated for root@localhost: ?dV?_49?hc.f
[root@localhost bin]# pwd
/usr/local/mysql/bin
[root@localhost bin]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
-bash: bin/mysql_install_db: No such file or directory
[root@localhost bin]# ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
-bash: ./bin/mysql_install_db: No such file or directory
[root@localhost bin]# sh bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
sh: bin/mysql_install_db: No such file or directory
[root@localhost bin]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
2022-08-07 07:12:36 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2022-08-07 07:12:36 [ERROR]   The data directory \'/usr/local/mysql/data\' already exist and is not empty.
[root@localhost bin]# rm -rf /usr/local/mysql/data/
[root@localhost bin]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
2022-08-07 07:13:23 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2022-08-07 07:13:27 [WARNING] The bootstrap log isn\'t empty:
2022-08-07 07:13:27 [WARNING] 2022-08-07T14:13:23.279025Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2022-08-07T14:13:23.279659Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2022-08-07T14:13:23.279668Z 0 [Warning] Changed limits: table_open_cache: 407 (requested 2000)

[root@localhost bin]# cd ../
[root@localhost mysql]# ll
total 276
drwxr-xr-x.  2 mysql mysql   4096 Aug  7 07:05 bin
drwxr-x---.  5 mysql mysql   4096 Aug  7 07:13 data
drwxr-xr-x.  2 mysql mysql     55 Aug  7 07:05 docs
drwxr-xr-x.  3 mysql mysql   4096 Aug  7 07:05 include
drwxr-xr-x.  5 mysql mysql    230 Aug  7 07:05 lib
-rw-r--r--.  1 mysql mysql 259199 Sep  6  2021 LICENSE
drwxr-xr-x.  4 mysql mysql     30 Aug  7 07:05 man
-rw-r--r--.  1 mysql mysql    566 Sep  6  2021 README
drwxr-xr-x. 28 mysql mysql   4096 Aug  7 07:05 share
drwxr-xr-x.  2 mysql mysql     90 Aug  7 07:05 support-files
[root@localhost mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chown 777 my.cnf
chown: cannot access ‘my.cnf’: No such file or directory
[root@localhost mysql]# chown 777 /etc/my.cnf
[root@localhost mysql]# /etc/init.d/mysqld restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL.Logging to \'/usr/local/mysql/data/localhost.localdomain.err\'.
2022-08-07T14:14:23.991592Z mysqld_safe Directory \'/var/lib/mysql\' for UNIX socket file don\'t exists.
 ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).
[root@localhost mysql]# mysql]# ps aux|grep mysql
bash: mysql]#: command not found...
[root@localhost mysql]# ps aux|grep mysql
root      14366  0.0  0.0 112808   964 pts/1    R+   07:15   0:00 grep --color=auto mysql
[root@localhost mysql]# kill -9 14366
-bash: kill: (14366) - No such process
[root@localhost mysql]# /usr/local/mysql/bin/mysqld_safe: line 198: 32684 Killed                  nohup /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=CDH-141.err --pid-file=/usr/local/mysql/data/CDH-141.pid --port=3323 < /dev/null > /dev/null 2>&1
[root@localhost mysql]# ps aux|grep mysql
root      14670  0.0  0.0 112808   968 pts/1    S+   07:15   0:00 grep --color=auto mysql
[root@localhost mysql]# /etc/init.d/mysqld restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL.Logging to \'/usr/local/mysql/data/localhost.localdomain.err\'.
2022-08-07T14:15:57.588824Z mysqld_safe Directory \'/var/lib/mysql\' for UNIX socket file don\'t exists.
 ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).
[root@localhost mysql]# service mysqld start
Starting MySQL.Logging to \'/usr/local/mysql/data/localhost.localdomain.err\'.
2022-08-07T14:16:30.536032Z mysqld_safe Directory \'/var/lib/mysql\' for UNIX socket file don\'t exists.
 ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).
[root@localhost mysql]# cat /usr/local/mysql/data/localhost.localdomain.err
cat: /usr/local/mysql/data/localhost.localdomain.err: No such file or directory
[root@localhost mysql]# cd  /usr/local/mysql/data/
[root@localhost data]# ll
total 110660
-rw-r-----. 1 mysql mysql       56 Aug  7 07:13 auto.cnf
-rw-------. 1 mysql mysql     1676 Aug  7 07:13 ca-key.pem
-rw-r--r--. 1 mysql mysql     1112 Aug  7 07:13 ca.pem
-rw-r--r--. 1 mysql mysql     1112 Aug  7 07:13 client-cert.pem
-rw-------. 1 mysql mysql     1676 Aug  7 07:13 client-key.pem
-rw-r-----. 1 mysql mysql      436 Aug  7 07:13 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 Aug  7 07:13 ibdata1
-rw-r-----. 1 mysql mysql 50331648 Aug  7 07:13 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 Aug  7 07:13 ib_logfile1
drwxr-x---. 2 mysql mysql     4096 Aug  7 07:13 mysql
drwxr-x---. 2 mysql mysql     8192 Aug  7 07:13 performance_schema
-rw-------. 1 mysql mysql     1676 Aug  7 07:13 private_key.pem
-rw-r--r--. 1 mysql mysql      452 Aug  7 07:13 public_key.pem
-rw-r--r--. 1 mysql mysql     1112 Aug  7 07:13 server-cert.pem
-rw-------. 1 mysql mysql     1680 Aug  7 07:13 server-key.pem
drwxr-x---. 2 mysql mysql     8192 Aug  7 07:13 sys
[root@localhost data]# chown -R mysql:mysql /var/lib/mysql
chown: cannot access ‘/var/lib/mysql’: No such file or directory
[root@localhost data]# mkdir -p /var//lib/mysql
[root@localhost data]# chown -R mysql:mysql /var/lib/mysql
[root@localhost data]# systemctl start mysql
Failed to start mysql.service: Unit not found.
[root@localhost data]# systemctl start mysqld
Failed to start mysqld.service: Unit not found.
[root@localhost data]# service mysqld start
Starting MySQL.Logging to \'/usr/local/mysql/data/localhost.localdomain.err\'.
 SUCCESS!
[root@localhost data]# chkconfig --level 35 mysqld on
[root@localhost data]# 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
[root@localhost data]# service mysqld status
 SUCCESS! MySQL running (16587)
[root@localhost data]# vim /etc/profile
[root@localhost data]# source /etc/profile
[root@localhost data]#  cat /root/.mysql_secret
# Password set for user \'root@localhost\' at 2022-08-07 07:13:23
SBjo&twpMd>K
[root@localhost data]# mysql -uroot -p
Enter password:
mysql: Character set \'utf8-mb4\' is not a compiled character set and is not specified in the \'/usr/local/mysql/share/charsets/Index.xml\' file
mysql: Character set \'utf8-mb4\' is not a compiled character set and is not specified in the \'/usr/local/mysql/share/charsets/Index.xml\' file
ERROR 2019 (HY000): Can\'t initialize character set utf8-mb4 (path: /usr/local/mysql/share/charsets/)
[root@localhost data]# vim /etc/my.cnf
[root@localhost data]# systemctl restart mysql
[root@localhost data]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user \'root\'@\'localhost\' (using password: YES)
[root@localhost data]# 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.36

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> set PASSWORD = PASSWORD(\'MGuoDu2022\');
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

mysql>exit;
Bye

[root@localhost data]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \\g. Your MySQL connection id is 9 Server version: 5.7.36 MySQL Community Server (GPL) Copyright (c) 2000, 2021, Oracle and/or its affiliates. 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> GRANT ALL PRIVILEGES ON *.* TO \'root\'@\'%\' IDENTIFIED BY \'MGuoDu2022\' WITH GRANT OPTION; Query OK, 0 rows affected, 1 warning (0.06 sec) mysql> select host,user from user; ERROR 1046 (3D000): No database selected mysql> service mysqld restart mysql> exit; Bye
[root@localhost data]
# service mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS! [root@localhost data]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2022-08-07 06:50:58 PDT; 39min ago Docs: man:firewalld(1) Main PID: 696 (firewalld) Tasks: 2 Memory: 10.6M CGroup: /system.slice/firewalld.service └─696 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid Aug 07 06:50:57 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon... Aug 07 06:50:58 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon. Aug 07 06:50:58 localhost.localdomain firewalld[696]: WARNING: AllowZoneDrifting is enabled. This is considered an insec... now. Hint: Some lines were ellipsized, use -l to show in full. [root@localhost data]# [root@localhost data]# firewall-cmd --permanent --add-port=3506/tcp success [root@localhost data]# [root@localhost data]# firewall-cmd --reload success [root@localhost data]# vim /etc/my.cnf [root@localhost data]# systemctl restart mysql [root@localhost data]#

转载至:https://www.cnblogs.com/elfin/p/11379251.html

 


来源:https://www.cnblogs.com/JimmyThomas/p/16571278.html
本站部分图文来源于网络,如有侵权请联系删除。

未经允许不得转载:百木园 » Centos7环境使用Mysql离线安装包安装Mysql5.7

相关推荐

  • 暂无文章