Centos7 配置Mysql5.6.29

本文提供了一步一步的指南,用于在CentOS7系统中使用RPM方式安装MySQL 5.6,并解决了安装过程中可能出现的错误,如加载共享库失败和启动失败等问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.修改主机名

centos7永久更改主机名

https://www.cnblogs.com/me80/p/7218488.html?utm_source=itdadao&utm_medium=referral

2. 安装jdk

3.安装mysql

Centos7下RPM方式安装mysql-5.6.24

http://blog.youkuaiyun.com/u013276589/article/details/51613760

Linux(CentOS7)下rpm方式安装mysql5.6.29

https://www.jianshu.com/p/e23d22022c53

mysql初始化出现:Installing MySQL system tables.../usr/local/mysql/bin/mysqld: error while loading shared

http://blog.youkuaiyun.com/songmao3145/article/details/77676402


修改linux主机名导致mysql启动失败

http://blog.youkuaiyun.com/esonbest1234/article/details/50729050


rm -rf /run/lock/subsys/mysql
rm -rf /etc/selinux/targeted/modules/active/modules/mysql.pp
rm -rf /root/.mysql_secret
rm -rf /root/.mysql_history
rm -rf /var/lib/mysql
rm -rf /var/lib/mysql/mysql
rm -rf /usr/lib/firewalld/services/mysql.xml
rm -rf /usr/lib64/mysql
rm -rf /usr/share/man/man5/mysql_table.5.gz



rm -rf /run/lock/subsys/mysql
rm -rf /etc/rc.d/init.d/mysql
rm -rf /etc/logrotate.d/mysql
rm -rf /var/lib/mysql
rm -rf /var/lib/mysql/mysql
rm -rf /usr/bin/mysql
rm -rf /usr/lib64/mysql
rm -rf /usr/share/mysql
rm -rf /usr/include/mysql
rm -rf /usr/include/mysql/mysql
rm -rf /usr/local/mysql

rpm -e –nodeps

 rpm -qa | grep -i mariadb-libs
1、CentOs7版本默认情况下安装了mariadb-libs,必须先卸载才可以继续安装MySql。
    
    a)  查找以前是否安装mariadb-libs
    rpm -qa | grep -i mariadb-libs

    yum remove mariadb-libs-5.5.35-3.el7.x86_64

    [root@besskyim ~]# yum remove mariadb-libs-5.5.35-3.el7.x86_64
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.35-3.el7 will be erased
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Running transaction check
---> Package postfix.x86_64 2:2.10.1-6.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================================
 Package                     Arch                  Version                       Repository                Size
================================================================================================================
Removing:
 mariadb-libs                x86_64                1:5.5.35-3.el7                @anaconda                4.4 M
Removing for dependencies:
 postfix                     x86_64                2:2.10.1-6.el7                @anaconda                 12 M

Transaction Summary
================================================================================================================
Remove  1 Package (+1 Dependent package)

Installed size: 17 M
Is this ok [y/N]:

Installed size: 17 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : 2:postfix-2.10.1-6.el7.x86_64                                                                1/2
  Erasing    : 1:mariadb-libs-5.5.35-3.el7.x86_64                                                           2/2
  Verifying  : 1:mariadb-libs-5.5.35-3.el7.x86_64                                                           1/2
  Verifying  : 2:postfix-2.10.1-6.el7.x86_64                                                                2/2

Removed:
  mariadb-libs.x86_64 1:5.5.35-3.el7                                                                            

Dependency Removed:
  postfix.x86_64 2:2.10.1-6.el7                                                                                 

Complete!
[root@besskyim ~]#

如果在安装过程中有提示找不到Perl或者net-tools等,按提示yum安装即可
yum install Perl* 或者 yum install Perl*
yum install net-tools

yum install -y perl-Module-Install.noarch

yum install libaio




创建mysql, cd /usr/local/

mkdir mysql

直接上传到/usr/local/mysql

解开一个tar 安装包 MySQL-5.6.39-1.el7.x86_64.rpm-bundle.tar

tar xvf MySQL-5.6.39-1.el7.x86_64.rpm-bundle.tar



目录mysql下现在有7个文件
rpm -ivh MySQL-server-5.6.39-1.el7.x86_64.rpm --force --nodeps
rpm -ivh MySQL-client-5.6.39-1.el7.x86_64.rpm --force --nodeps


[root@besskyim mysql]# tar xvf MySQL-5.6.39-1.el7.x86_64.rpm-bundle.tar
MySQL-shared-compat-5.6.39-1.el7.x86_64.rpm
MySQL-client-5.6.39-1.el7.x86_64.rpm
MySQL-devel-5.6.39-1.el7.x86_64.rpm
MySQL-server-5.6.39-1.el7.x86_64.rpm
MySQL-shared-5.6.39-1.el7.x86_64.rpm
MySQL-test-5.6.39-1.el7.x86_64.rpm
MySQL-embedded-5.6.39-1.el7.x86_64.rpm
[root@besskyim mysql]# ls
MySQL-5.6.39-1.el7.x86_64.rpm-bundle.tar  MySQL-server-5.6.39-1.el7.x86_64.rpm
MySQL-client-5.6.39-1.el7.x86_64.rpm      MySQL-shared-5.6.39-1.el7.x86_64.rpm
MySQL-devel-5.6.39-1.el7.x86_64.rpm       MySQL-shared-compat-5.6.39-1.el7.x86_64.rpm

MySQL-embedded-5.6.39-1.el7.x86_64.rpm    MySQL-test-5.6.39-1.el7.x86_64.rpm


[root@besskyim mysql]# rpm -ivh MySQL-server-5.6.39-1.el7.x86_64.rpm --force --nodeps
warning: MySQL-server-5.6.39-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:MySQL-server-5.6.39-1.el7        ################################# [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
/usr/sbin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
[root@besskyim mysql]#

yum install libaio

[root@besskyim mysql]# yum install libaio
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: ftp.sjtu.edu.cn
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================================
 Package                 Arch                    Version                            Repository             Size
================================================================================================================
Installing:
 libaio                  x86_64                  0.3.109-13.el7                     base                   24 k

Transaction Summary
================================================================================================================
Install  1 Package

Total download size: 24 k
Installed size: 38 k
Is this ok [y/d/N]: y
Downloading packages:
libaio-0.3.109-13.el7.x86_64.rpm                                                         |  24 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 3 pre-existing rpmdb problem(s), 'yum check' output follows:
MySQL-server-5.6.39-1.el7.x86_64 has missing requires of libaio.so.1()(64bit)
MySQL-server-5.6.39-1.el7.x86_64 has missing requires of libaio.so.1(LIBAIO_0.1)(64bit)
MySQL-server-5.6.39-1.el7.x86_64 has missing requires of libaio.so.1(LIBAIO_0.4)(64bit)
  Installing : libaio-0.3.109-13.el7.x86_64                                                                 1/1
  Verifying  : libaio-0.3.109-13.el7.x86_64                                                                 1/1

Installed:
  libaio.x86_64 0:0.3.109-13.el7                                                                                

Complete!


[root@besskyim mysql]# rpm -ivh MySQL-server-5.6.39-1.el7.x86_64.rpm --force --nodeps
warning: MySQL-server-5.6.39-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Giving mysqld 5 seconds to exit nicely
Updating / installing...
   1:MySQL-server-5.6.39-1.el7        ################################# [100%]
[root@besskyim mysql]#



rpm -ivh MySQL-client-5.6.39-1.el7.x86_64.rpm --force --nodeps


[root@besskyim mysql]# rpm -ivh MySQL-client-5.6.39-1.el7.x86_64.rpm --force --nodeps
warning: MySQL-client-5.6.39-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:MySQL-client-5.6.39-1.el7        ################################# [100%]
[root@besskyim mysql]#

[root@besskyim mysql]# service mysql start  
Starting MySQL. ERROR! The server quit without updating PID file (/var/lib/mysql/besskyim.pid).
[root@besskyim mysql]# reboot
chmod -R 755 /var/lib/mysql

修改linux主机名导致mysql启动失败
 yum install lsof 

ERROR! The server quit without updating PID file解决

今天公司同事让我帮忙解决下测试服务器上mysql无法启动的问题,登上去一看,启动mysql报Starting MySQL ....... ERROR! The server quit without updating PID file(/var/lib/mysql/ip-10-0-1-112.pid). 如下图:
点击查看原图
  我的第一反应是硬盘是不是没有空间了,df -h查看硬盘空间,根目录已经100%了,马上用find / -size +50M -exec ls -lh {} \;来找出大于50m的文件,删除了几个无用的安装包之后,硬盘空间清理出来了,再启动mysql,还是报刚刚的错误,我进到/var/lib/mysql/下,以为是pid文件没有删除,手动删除之后再启动,居然还是报一样的错误,估计这个时候大家都要网上搜索找解决办法了吧,傍边一个同事提醒了一句要不看看错误日志,马上查看mysql错误日志,如下图:
点击查看原图
  这里错误日志居然说uft8是未知参数,好吧,在/etc/my.cnf里把default-character-set=uft8这项给注释了,再启动mysql,终于看到了启动成功的信息.

ps:

  以这个案例来说,就是要大家以后遇到问题还是多看看日志,避免耽搁时间解决问题.


四、解压安装包,安装

4.1 安装MySQL-service

[root@localhost mysql]#  rpm -ivh MySQL-server-5.6.39-1.el7.x86_64.rpm --force --nodeps
warning: MySQL-server-5.6.39-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:MySQL-server-5.6.39-1.el7        ################################# [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
2018-03-01 23:40:10 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-03-01 23:40:10 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-03-01 23:40:10 0 [Note] /usr/sbin/mysqld (mysqld 5.6.39) starting as process 22637 ...
2018-03-01 23:40:10 22637 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-03-01 23:40:10 22637 [Note] InnoDB: The InnoDB memory heap is disabled
2018-03-01 23:40:10 22637 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-03-01 23:40:10 22637 [Note] InnoDB: Memory barrier is not used
2018-03-01 23:40:10 22637 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-03-01 23:40:10 22637 [Note] InnoDB: Using Linux native AIO
2018-03-01 23:40:10 22637 [Note] InnoDB: Using CPU crc32 instructions
2018-03-01 23:40:10 22637 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-03-01 23:40:10 22637 [Note] InnoDB: Completed initialization of buffer pool
2018-03-01 23:40:10 22637 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2018-03-01 23:40:10 22637 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2018-03-01 23:40:10 22637 [Note] InnoDB: Database physically writes the file full: wait...
2018-03-01 23:40:10 22637 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2018-03-01 23:40:10 22637 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2018-03-01 23:40:10 22637 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2018-03-01 23:40:10 22637 [Warning] InnoDB: New log files created, LSN=45781
2018-03-01 23:40:10 22637 [Note] InnoDB: Doublewrite buffer not found: creating new
2018-03-01 23:40:10 22637 [Note] InnoDB: Doublewrite buffer created
2018-03-01 23:40:11 22637 [Note] InnoDB: 128 rollback segment(s) are active.
2018-03-01 23:40:11 22637 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-03-01 23:40:11 22637 [Note] InnoDB: Foreign key constraint system tables created
2018-03-01 23:40:11 22637 [Note] InnoDB: Creating tablespace and datafile system tables.
2018-03-01 23:40:11 22637 [Note] InnoDB: Tablespace and datafile system tables created.
2018-03-01 23:40:11 22637 [Note] InnoDB: Waiting for purge to start
2018-03-01 23:40:11 22637 [Note] InnoDB: 5.6.39 started; log sequence number 0
A random root password has been set. You will find it in '/root/.mysql_secret'.
2018-03-01 23:40:11 22637 [Note] Binlog end
2018-03-01 23:40:11 22637 [Note] InnoDB: FTS optimize thread exiting.
2018-03-01 23:40:11 22637 [Note] InnoDB: Starting shutdown...
2018-03-01 23:40:12 22637 [Note] InnoDB: Shutdown completed; log sequence number 1625977


2018-03-01 23:40:12 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-03-01 23:40:12 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-03-01 23:40:12 0 [Note] /usr/sbin/mysqld (mysqld 5.6.39) starting as process 22659 ...
2018-03-01 23:40:12 22659 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-03-01 23:40:12 22659 [Note] InnoDB: The InnoDB memory heap is disabled
2018-03-01 23:40:12 22659 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-03-01 23:40:12 22659 [Note] InnoDB: Memory barrier is not used
2018-03-01 23:40:12 22659 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-03-01 23:40:12 22659 [Note] InnoDB: Using Linux native AIO
2018-03-01 23:40:12 22659 [Note] InnoDB: Using CPU crc32 instructions
2018-03-01 23:40:12 22659 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-03-01 23:40:12 22659 [Note] InnoDB: Completed initialization of buffer pool
2018-03-01 23:40:12 22659 [Note] InnoDB: Highest supported file format is Barracuda.
2018-03-01 23:40:12 22659 [Note] InnoDB: 128 rollback segment(s) are active.
2018-03-01 23:40:12 22659 [Note] InnoDB: Waiting for purge to start
2018-03-01 23:40:12 22659 [Note] InnoDB: 5.6.39 started; log sequence number 1625977
2018-03-01 23:40:13 22659 [Note] Binlog end
2018-03-01 23:40:13 22659 [Note] InnoDB: FTS optimize thread exiting.
2018-03-01 23:40:13 22659 [Note] InnoDB: Starting shutdown...
2018-03-01 23:40:14 22659 [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

五、测试

5.1 测试启动和关闭

[root@localhost mysql]#
[root@localhost mysql]# service mysql start
Starting MySQL. SUCCESS!
[root@localhost mysql]#
[root@localhost mysql]# service mysql stop
Shutting down MySQL.. SUCCESS!
mysqld_safe –user=mysql –skip-grant-tables –skip-networking & mysql -u root mysql

[root@localhost mysql]# mysqld_safe –user=mysql –skip-grant-tables –skip-networking & mysql -u root mysql
[1] 22847
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@localhost mysql]# 180301 23:44:17 mysqld_safe Logging to '/var/lib/mysql/localhost.localdomain.err'.
180301 23:44:17 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
180301 23:44:19 mysqld_safe mysqld from pid file /var/lib/mysql/localhost.localdomain.pid ended


htLcggg82WZAKetX

5.2查看root账号的密码


cat /root/.mysql_secret

service mysql start
mysql -uroot -phtLcggg82WZAKetX

六、登录更换密码

root@localhost mysql]# mysql -uroot -phtLcggg82WZAKetX
Warning: Using a password on the command line interface can be insecure.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

6.1 启动mysql

[root@localhost mysql]# service mysql start
Starting MySQL. SUCCESS!
[root@localhost mysql]# mysql -uroot -phtLcggg82WZAKetX
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.39

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

6.2 设置新密码

set password = password('xxxxxx');

mysql> set password = password('xxxxxx');
Query OK, 0 rows affected (0.00 sec)

mysql>

七 开启远程连接

grant all privileges on *.* to 'root'@'%' identified by 'xxxxxx' with grant option;


mysql -uroot -pxxxxxxxx

八  配置数据库服务端和客户端编码

mysql> SHOW VARIABLES LIKE 'character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

mysql>
[root@localhost mysql]# service mysql stop
error: Found option without preceding group in config file: /etc/my.cnf at line: 7
Fatal error in defaults handling. Program aborted
Shutting down MySQL.. SUCCESS!
[root@localhost mysql]#
lower_case_table_names=1  

[root@localhost mysql]# service mysql stop
error: Found option without preceding group in config file: /etc/my.cnf at line: 7
Fatal error in defaults handling. Program aborted
Shutting down MySQL.. SUCCESS!
[root@localhost mysql]# service mysql start
error: Found option without preceding group in config file: /etc/my.cnf at line: 7
Fatal error in defaults handling. Program aborted
Starting MySQL. ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).
[root@localhost mysql]# vi /etc/my.cnf
[root@localhost mysql]# service mysql stop
 ERROR! MySQL server PID file could not be found!
[root@localhost mysql]# service mysql start
Starting MySQL... ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).
[root@localhost mysql]#


[mysqld]
character-set-server=utf8 //注意这里和client,mysql加的是不一样的!!!!!!!!!!!!!!
注意: mysql到了5.5版本, [mysql] 项内可以写default-character-set=utf8, 但是[mysqld] 项内不能再这么写了,而是必须写:character-set-server=utf8
以上3个都搞定后重启mysql,执行
mysql> SHOW VARIABLES LIKE ‘character%’;
即会显示除了character_set_filesystem外其他全部为utf8

九、关闭防火墙

        systemctl stop firewalld
        systemctl disable firewalld.service
       



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值