在CentOS 7 上 安装部署 MySQL 5.7.25 并配置

近日在华为云平台上分配的VM上安装部署MySQL和Nginx服务,遇到了很多坑点,首当其冲的便是OS系统组件的严重缺失和端口封锁,很可能是因为这个CentOS镜像属于精度精简的OEM镜像。
经测试,MySQL的 RPM bundle 、Redhat compress tar 及 MySQL 5.7.29 gentic compress tar 都不能正常安装和配置启动服务,仅 MySQL 5.7.25 gentic compress tar 解压配置后可以正常启动服务。
以下是本次安装MySQL的详细记录:

remove mysql or mariadb installed

[root@ha-dsjjcjk-vm01 ~]# rpm -qa | grep mysql
[root@ha-dsjjcjk-vm01 ~]# rpm -qa | grep mari
mariadb-libs-5.5.56-2.el7.x86_64
[root@ha-dsjjcjk-vm01 ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
[root@ha-dsjjcjk-vm01 ~]# rpm -qa | grep mari
[root@ha-dsjjcjk-vm01 ~]# ls /etc/ | grep cnf
[root@ha-dsjjcjk-vm01 ~]# rm /etc/m
machine-id mail.rc man_db.conf modprobe.d/ motd
magic makedumpfile.conf.sample mke2fs.conf modules-load.d/ mtab
[root@ha-dsjjcjk-vm01 ~]# rm /etc/my.cnf
rm: cannot remove ‘/etc/my.cnf’: No such file or directory
[root@ha-dsjjcjk-vm01 ~]#

[root@ha-dsjjcjk-vm01 ~]# ls
anaconda-ks.cfg CloudResetPwdAgent CloudResetPwdAgent.zip upload
[root@ha-dsjjcjk-vm01 ~]# cd upload/src/tar/
[root@ha-dsjjcjk-vm01 tar]# ls
mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
[root@ha-dsjjcjk-vm01 tar]# tar -xzvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
mysql-5.7.25-linux-glibc2.12-x86_64/bin/myisam_ftdump
mysql-5.7.25-linux-glibc2.12-x86_64/bin/myisamchk
mysql-5.7.25-linux-glibc2.12-x86_64/bin/myisamlog
mysql-5.7.25-linux-glibc2.12-x86_64/bin/myisampack
mysql-5.7.25-linux-glibc2.12-x86_64/bin/mysql
mysql-5.7.25-linux-glibc2.12-x86_64/bin/mysql_client_test_embedded
......................................................................................................................................................................
mysql-5.7.25-linux-glibc2.12-x86_64/support-files/mysql.server
mysql-5.7.25-linux-glibc2.12-x86_64/docs/INFO_BIN
mysql-5.7.25-linux-glibc2.12-x86_64/docs/INFO_SRC
[root@ha-dsjjcjk-vm01 tar]#

[root@ha-dsjjcjk-vm01 tar]# cd /usr/local/
[root@ha-dsjjcjk-vm01 local]# ls
bin etc games include lib lib64 libexec mysql-5.7.25-linux-glibc2.12-x86_64 sbin share src
[root@ha-dsjjcjk-vm01 local]# mv mysql-5.7.25-linux-glibc2.12-x86_64/ mysql
[root@ha-dsjjcjk-vm01 local]# ls
bin etc games include lib lib64 libexec mysql sbin share src
[root@ha-dsjjcjk-vm01 local]#

[root@ha-dsjjcjk-vm01 local]# id mysql
uid=1000(mysql) gid=1000(mysql) groups=1000(mysql)
[root@ha-dsjjcjk-vm01 local]# chown -R mysql mysql/
[root@ha-dsjjcjk-vm01 local]# chgrp -R mysql mysql/
[root@ha-dsjjcjk-vm01 local]# cd mysql/
[root@ha-dsjjcjk-vm01 mysql]# ls
bin COPYING docs include lib man README share support-files
[root@ha-dsjjcjk-vm01 mysql]# mkdir data
[root@ha-dsjjcjk-vm01 mysql]# chown -R mysql:mysql data
[root@ha-dsjjcjk-vm01 mysql]#

[root@ha-dsjjcjk-vm01 mysql]# pwd -P
/usr/local/mysql
[root@ha-dsjjcjk-vm01 mysql]# ls
bin COPYING data docs include lib man my.conf.txt README share support-files
[root@ha-dsjjcjk-vm01 mysql]# mv my.conf.txt my.conf
[root@ha-dsjjcjk-vm01 mysql]# ls
bin COPYING data docs include lib man my.conf README share support-files
[root@ha-dsjjcjk-vm01 mysql]# cat my.conf
[mysql]
socket=/var/lib/mysql/mysql.sock

default-character-set=utf8

[mysqld]
socket=/var/lib/mysql/mysql.sock

port = 3306

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

max_connections=200

character-set-server=utf8

default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
explicit_defaults_for_timestamp=true

[mysql.server]
user=mysql
basedir=/usr/local/mysql
[root@ha-dsjjcjk-vm01 mysql]#

install mysql

[root@ha-dsjjcjk-vm01 mysql]# pwd -P
/usr/local/mysql
[root@ha-dsjjcjk-vm01 mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2020-04-10 09:40:42 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2020-04-10 09:40:46 [WARNING] The bootstrap log isn't empty:
2020-04-10 09:40:46 [WARNING] 2020-04-10T01:40:42.877058Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2020-04-10T01:40:42.877755Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2020-04-10T01:40:42.877763Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
[root@ha-dsjjcjk-vm01 mysql]#

[root@ha-dsjjcjk-vm01 mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@ha-dsjjcjk-vm01 mysql]# chown 777 my.conf
[root@ha-dsjjcjk-vm01 mysql]# ls
bin COPYING data docs include lib man my.conf README share support-files
[root@ha-dsjjcjk-vm01 mysql]# ls -l
total 44
drwxr-xr-x 2 mysql mysql 4096 Apr 10 09:26 bin
-rw-r--r-- 1 mysql mysql 17987 Dec 21 2018 COPYING
drwxr-xr-x 5 mysql mysql 4096 Apr 10 09:40 data
drwxr-xr-x 2 mysql mysql 55 Apr 10 09:26 docs
drwxr-xr-x 3 mysql mysql 4096 Apr 10 09:26 include
drwxr-xr-x 5 mysql mysql 230 Apr 10 09:26 lib
drwxr-xr-x 4 mysql mysql 30 Apr 10 09:26 man
-rw-r--r-- 1 777 root 613 Apr 10 09:36 my.conf
-rw-r--r-- 1 mysql mysql 2478 Dec 21 2018 README
drwxr-xr-x 28 mysql mysql 4096 Apr 10 09:26 share
drwxr-xr-x 2 mysql mysql 90 Apr 10 09:26 support-files
[root@ha-dsjjcjk-vm01 mysql]# chmod +x /etc/init.d/mysqld
[root@ha-dsjjcjk-vm01 mysql]#

[root@ha-dsjjcjk-vm01 mysql]# /etc/init.d/mysqld restart
ERROR! MySQL server PID file could not be found!
Starting MySQL.Logging to '/usr/local/mysql/data/ha-dsjjcjk-vm01.novalocal.err'.
SUCCESS!
[root@ha-dsjjcjk-vm01 mysql]# ps -ef | grep 3306
root 21631 19191 0 09:45 pts/0 00:00:00 grep --color=auto 3306
[root@ha-dsjjcjk-vm01 mysql]# ps -aux | grep mysql
root 21514 0.0 0.0 113308 1620 pts/0 S 09:44 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/ha-dsjjcjk-vm01.novalocal.pid
mysql 21599 0.3 1.1 1117376 180320 pts/0 Sl 09:44 0:00 /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=ha-dsjjcjk-vm01.novalocal.err --pid-file=/usr/local/mysql/data/ha-dsjjcjk-vm01.novalocal.pid
root 21634 0.0 0.0 112704 972 pts/0 S+ 09:45 0:00 grep --color=auto mysql
[root@ha-dsjjcjk-vm01 mysql]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@ha-dsjjcjk-vm01 mysql]# chkconfig mysqld on
[root@ha-dsjjcjk-vm01 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@ha-dsjjcjk-vm01 mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@ha-dsjjcjk-vm01 mysql]# service mysqld status
SUCCESS! MySQL running (21751)
[root@ha-dsjjcjk-vm01 mysql]#

[root@ha-dsjjcjk-vm01 mysql]# cat /root/.mysql_secret
*# Password set for user 'root@localhost' at 2020-04-10 09:40:42

Lemwj!a2bL%
[root@ha-dsjjcjk-vm01 mysql]#

[root@ha-dsjjcjk-vm01 mysql]# mysql -u root -p
-bash: mysql: command not found
[root@ha-dsjjcjk-vm01 mysql]# ln -s /usr/local/mysql/bin/mysql /usr/bin/
[root@ha-dsjjcjk-vm01 mysql]#
[root@ha-dsjjcjk-vm01 mysql]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@ha-dsjjcjk-vm01 mysql]#
【这个报错主要是和skip-grant-tables有关,解决思路有二:一是在命令行用mysqldsafe --skip-grant-tables & 跳过;二是修改my.conf文件。待进入MySQL后,再重设登录密码】
[root@ha-dsjjcjk-vm01 mysql]# /usr/local/mysql/bin/mysqladmin -u root -p shutdown
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'
[root@ha-dsjjcjk-vm01 mysql]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
[root@ha-dsjjcjk-vm01 mysql]# pwd -P
/usr/local/mysql
[root@ha-dsjjcjk-vm01 mysql]# ls
bin COPYING data docs include lib man my.conf README share support-files
[root@ha-dsjjcjk-vm01 mysql]# cd bin/
[root@ha-dsjjcjk-vm01 bin]# ls
innochecksum mysql mysqld mysqlimport mysql_ssl_rsa_setup resolveip
lz4_decompress mysqladmin mysqld-debug mysql_install_db mysqltest_embedded resolve_stack_dump
myisamchk mysqlbinlog mysqld_multi mysql_plugin mysql_tzinfo_to_sql zlib_decompress
myisam_ftdump mysqlcheck mysqld_safe mysqlpump mysql_upgrade
myisamlog mysql_client_test_embedded mysqldump mysql_secure_installation mysqlxtest
myisampack mysql_config mysqldumpslow mysqlshow perror
my_print_defaults mysql_config_editor mysql_embedded mysqlslap replace
[root@ha-dsjjcjk-vm01 bin]# ./mysqld_safe --skip-grant-tables &
[1] 22716
[root@ha-dsjjcjk-vm01 bin]# 2020-04-10T02:15:33.729443Z mysqld_safe Logging to '/usr/local/mysql/data/ha-dsjjcjk-vm01.novalocal.err'.
2020-04-10T02:15:33.758961Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
^C
[root@ha-dsjjcjk-vm01 bin]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25 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> 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> select user,host,password from user;
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
mysql> select user from user;
+---------------+
| user |
+---------------+
| mysql.session |
| mysql.sys |
| root |
+---------------+
3 rows in set (0.00 sec)

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

mysql> delete from user where user='';
Query OK, 0 rows affected (0.00 sec)

[root@ha-dsjjcjk-vm01 bin]# mysql -uroot -p
Enter password: 【无需密码,直接回车】
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.25 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> 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> select user,host from user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)

mysql> update user set authentication_string = password('密码') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1

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

mysql> quit;
Bye
[root@ha-dsjjcjk-vm01 bin]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.25

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> use mysql
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by '密码';
Query OK, 0 rows affected (0.00 sec)

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

mysql> quit;
Bye
[root@ha-dsjjcjk-vm01 bin]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.25 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> 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> select user,host from user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)

mysql> quit;
Bye
[root@ha-dsjjcjk-vm01 bin]#
[root@ha-dsjjcjk-vm01 bin]# ps -ef | grep mysql
root 22716 19191 0 10:15 pts/0 00:00:00 /bin/sh ./mysqld_safe --skip-grant-tables
mysql 22791 22716 0 10:15 pts/0 00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --skip-grant-tables --log-error=ha-dsjjcjk-vm01.novalocal.err --pid-file=ha-dsjjcjk-vm01.novalocal.pid
root 22946 19191 0 10:19 pts/0 00:00:00 mysql -uroot -p
root 24237 19191 0 11:03 pts/0 00:00:00 grep --color=auto mysql
[root@ha-dsjjcjk-vm01 bin]# ps -ef | grep 3306
root 24239 19191 0 11:04 pts/0 00:00:00 grep --color=auto 3306
[root@ha-dsjjcjk-vm01 bin]#

[root@ha-dsjjcjk-vm01 mysql]# 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.25 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> 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> select user,host from user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)

mysql> grant all privileges on . to 'root'@'%' identified by '密码' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

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

mysql> quit;
Bye
[root@ha-dsjjcjk-vm01 mysql]#
[root@ha-dsjjcjk-vm01 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.25 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> 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> select host,user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | root |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
4 rows in set (0.00 sec)

mysql> grant all privileges on . to 'mysql'@'%' identified by '密码' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

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

mysql>quit;
Bye
[root@ha-dsjjcjk-vm01 ~]#

尽管云化产品供应商在不断地游说党政国企单位采购他们的云化产品,但是云化产品是否贴合于采购单位的业务需求、是否符合行业技术规范,仍是未知数。如果采购单位不做充分的业务需求特征分析和适用技术论证,就一刀切地盲目“上马云项目”,只怕最终的结果并不会如人所愿,甚至可以说是得不偿失。
当前中国大陆的云化产品供应商提供的云化产品,绝大多数仍是基于 Like OpenStack 套件 封装的,但云平台真的就是“包治百病的神药”、适用于所有典型的政企业务吗?各家采购单位热情高涨地上马“云项目”真的是业务需求推动的吗?
要知道,应用技术是为了解决具体业务需求而诞生的,离开具体业务需求而空谈应用技术,无论在何时都是没有实际意义的,徒增预算内资源的浪费罢了。
当前党政国企单位热情高涨地采购云化产品、大张旗鼓地上马“云化项目”,抛开政治因素不谈,恐怕也和当下急功近利、浮躁逐利、放弃实业的社会情绪有关,更有莫大干系的恐怕是云化产品供应商的销售代表。销售代表在向意向单位推销云化产品时,恐怕并没有协助这些单位做好业务需求调研、更遑论做技术适用论证了,他们更多的是夸大了具体产品的适用范围和功能特性,对于具体产品本身的不足和缺陷以及历史报告或产品测试过程中的不适用案例可能是隐晦地一笔带过或者是只字不提,采用“报喜不报忧”的心态,只讲好处、不讲不足,欺瞒性地引诱意向单位作出并非比较符合实际情况采购投资计划。
对于采购单位而言,一定要时刻关注本单位的具体业务需求变化,在立项前做好充足的业务需求调研和技术适用论证,以具体业务需求为依据、以实现需求的技术适用为准绳,有针对性地采购合适的产品。
对于产品供应商而言,一定要清楚自己所提供的产品的特性、功用、适用范围、测试与体验报告案例,派出的销售代表和技术顾问,则应该在充分了解意向单位的业务需求后,依据业务需求提供适用的产品选择。在功用雷同产品泛滥的状况下,供应商应该把产品增值服务放在营销的重点位置,而不仅仅是推销产品。
如果供应商对意向单位说,我们经过持续性的长期沟通,整理出了当前业务活动的痛点和比较符合实际的解决方案,并愿意为此后的技术升级改进提供必要的咨询服务,那么这就是在做服务,产品只是服务的物理载体。如果供应商对意向单位说,某某单位跟你们的业务比较相似,他们刚购买了我们的某某产品,你们要不要也来一套?这就是在推销产品,产品就是供应商的立命之本,卖出产品后这笔生意也就一锤定音了。

猜你喜欢

转载自blog.51cto.com/6286393/2486489
今日推荐