OS: Centos7.0
DB: Percona5.7
1. 通过yum安装
- ## 删除之前的mysql数据库, 我用的是centos7.再安装虚拟机的时候,预装了很多软件。所以mysql和mariadb的一些东西安装了。必须要删除掉
- rpm -qa | grep mysql
- rpm -qa | grep mariadb
-
- rpm -e mysql
- rpm -e --nodeps mysql
- yum remove mariadb-libs-5.5.41-2.el7_0.x86_64
-
- ## 安装其他依赖包:perl 和libaio
- yum -y install perl-Module-Install.noarch
- yum -y install libaio libaio-devel
-
- ## 配置yum安装源
- yum install https://www.percona.com/redir/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm ## 最新的是0.1-4
-
- ## 安装percona
- yum install Percona-Server-server-57
2. 通过rpm安装
- wget https://www.percona.com/downloads/Percona-Server-LATEST/Percona-Server-5.7.18-16/binary/redhat/7/x86_64/Percona-Server-5.7.18-16-rd7301f8-el7-x86_64-bundle.tar
-
- tar xvf Percona-Server-5.7.18-16-rd7301f8-el7-x86_64-bundle.tar
-
- rpm -ivh Percona-Server-shared-compat-57-5.7.18-16.1.el7.x86_64
- rpm -ivh Percona-Server-shared-57-5.7.18-16.1.el7.x86_64
- rpm -ivh Percona-Server-client-57-5.7.18-16.1.el7.x86_64
- rpm -ivh Percona-Server-server-57-5.7.18-16.1.el7.x86_64
3. 配置
- ## 配置用户组
- groupadd mysql
- useradd -r -g mysql mysql
-
- mysqld --initialize --user=mysql --datadir=/user/local/webserver/mysql ## 如果没报错,恭喜你很幸运
vim /etc/percona-server.conf.d/mysqld.cnf
- [mysqld]
-
- datadir=/usr/local/webserver/mysql
- socket=/usr/local/webserver/mysql/mysql.sock
-
- # initialize need
- explicit_defaults_for_timestamp=true
-
- # Disabling symbolic-links is recommended to prevent assorted security risks
- symbolic-links=0
-
- log-error=/var/log/mysqld.log
- pid-file=/var/run/mysqld/mysqld.pid
-
- [mysql]
- socket=/usr/local/webserver/mysql/mysql.sock
chown -R mysql:mysql /usr/local/webserver/mysql
service mysqld start ## 如果没报错,恭喜你很幸运。
4. 登录
- cat /var/log/mysqld.log | grep "temporary password" ## 找到root的初始密码。
-
- mysql -u root -p
-
- set password = password('root');
5. ERROR
- mysqld --initialize 报错:TIMESTAMP with implicit DEFAULT value is deprecated
从 5.6开始,timestamp 的默认行为已经是 deprecated
- vim /etc/percona-server.conf.d/mysqld.cnf
-
- explicit_defaults_for_timestamp=true ## 加上这段(显示指定默认值为timestamp类型的字段)
-
mysql --initialize 报错:initialize specified but the data directory has files in it. Aborting.
datadir 已经存在了。删除即可
-
service mysqld start 报错:InnoDB: .\ibdata1 must be writable > InnoDB 在启动时需要配置LOG File的目录,如果没有制定目录,则会在MySQL Data目录下创建2个日志文件ib_logfile0 and ib_logfile1,在创建的时候需要确保MYSQL拥有对该目录的权限。
- ps -ef | grep mysqld
- kill 21222 ## kill掉mysqld的进程
- rm /usr/local/webserver/mysql/ib_logfil*
- service mysqld start
- service mysqld start 报错:Could not create unix socket lock file /user/lib/mysql/mysql.sock.lock.
- ## 很简单的问题。加权限即可
- chown -R mysql:mysql /user/lib/mysql/
6. 总结
安装mysql的数据库必要步骤有:
- 安装依赖包
- 安装mysql数据库
- 初始化服务(mysqld --initialize)
- 修改配置文件,配置datadir目录权限和用户
- 启动服务,链接数据库
参考资料
- MySQL 5.6 中TIMESTAMP with implicit DEFAULT value is deprecated错误
- MYSQL 服务无法启动,错误日志:InnoDB: .\ibdata1 must be writable
- 如何在 CentOS 7 上安装 Percona服务器
- percona5.7 源码安装
<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">