MySQL 二进制安装及配置

部署环境 Centos 7.7
下载地址 https://downloads.mysql.com/archives/community/
数据库版本 mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
MySQL.png
安装前的清理:
1. mariadb-libs-5.5.64-1.el7.x86_64

[root@deploy ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.64-1.el7.x86_64
[root@deploy ~]# yum remove -y mariadb-libs-5.5.64-1.el7.x86_64

[root@deploy ~]# ls
mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
[root@deploy ~]# yum install -y libaio-devel
[root@deploy ~]# useradd -s /sbin/nologin -M mysql
[root@deploy ~]# tar xf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@deploy ~]# ln -s /usr/local/mysql-5.7.28-linux-glibc2.12-x86_64/ /usr/local/mysql
[root@deploy ~]# chown -R mysql.mysql /usr/local/mysql/

设置环境变量

方法一: 全局变量 ( 推荐使用 )
cat >> /etc/profile << EOF
export PATH=/usr/local/mysql/bin:\$PATH
EOF
source /etc/profile

----------------------------------------
方法二: 用户变量
cat > /etc/profile.d/MySQL.sh << EOF
#!/bin/bash
export PATH=/usr/local/mysql/bin:\$PATH
EOF
source /etc/profile.d/MySQL.sh

MySQL默认配置文件

cat > /etc/my.cnf << EOF
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
EOF

MySQL5.6 数据库初始化

[root@deploy ~]# /usr/local/mysql/scripts/mysql_install_db

MySQL5.7 数据库初始化

方法一: initialize-insecure ( 推荐使用 )
1. 没有限制, 没有临时密码
[root@deploy ~]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
2020-02-21T17:33:25.317663Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-02-21T17:33:25.602198Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-02-21T17:33:25.645803Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-02-21T17:33:25.703876Z 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: 43e20724-54d0-11ea-a34a-000c295939bd.
2020-02-21T17:33:25.704897Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-02-21T17:33:26.216962Z 0 [Warning] CA certificate ca.pem is self signed.
2020-02-21T17:33:26.471497Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.


方法二: initialize ( 不建议 )
1. 对于密码复杂度进行定制:12位,4种 
2. 密码过期时间:180天
3. 给root用户设置临时密码
[root@deploy ~]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
2020-02-21T17:22:38.043403Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-02-21T17:22:38.440672Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-02-21T17:22:38.507196Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-02-21T17:22:38.564241Z 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: c2285b2a-54ce-11ea-948b-000c295939bd.
2020-02-21T17:22:38.567279Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-02-21T17:22:39.271892Z 0 [Warning] CA certificate ca.pem is self signed.
2020-02-21T17:22:39.345435Z 1 [Note] A temporary password is generated for root@localhost: 1&lQd4x9_AFM

查看临时密码
[root@deploy ~]# cat /data/mysql/mysql.log |grep "A temporary password is generated for"
2020-02-22T23:49:30.243987Z 1 [Note] A temporary password is generated for root@localhost: eC;Wi:asS0Z/

修改临时密码
[root@mysql_02 opt]# mysqladmin -uroot -p'thrfroA=y0co' password 123456
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.


使用systemd管理mysql

cat > /etc/systemd/system/mysqld.service << EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE=5000
EOF

启动MySQL服务

[root@deploy ~]# systemctl start mysqld.service 
[root@deploy ~]# systemctl status mysqld.service 
● mysqld.service - MySQL Server
   Loaded: loaded (/etc/systemd/system/mysqld.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2020-02-22 07:29:29 CST; 3s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 1459 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─1459 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf

Feb 22 07:29:30 mysql_02 mysqld[1459]: 2020-02-21T23:29:30.343474Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
Feb 22 07:29:30 mysql_02 mysqld[1459]: 2020-02-21T23:29:30.347834Z 0 [Note] InnoDB: Loading buffer pool(s) from /data/mysql/ib_buffer_pool
Feb 22 07:29:30 mysql_02 mysqld[1459]: 2020-02-21T23:29:30.350092Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200222  7:29:30
Feb 22 07:29:30 mysql_02 mysqld[1459]: 2020-02-21T23:29:30.350918Z 0 [Note] IPv6 is available.
Feb 22 07:29:30 mysql_02 mysqld[1459]: 2020-02-21T23:29:30.350954Z 0 [Note]   - '::' resolves to '::';
Feb 22 07:29:30 mysql_02 mysqld[1459]: 2020-02-21T23:29:30.350973Z 0 [Note] Server socket created on IP: '::'.
Feb 22 07:29:30 mysql_02 mysqld[1459]: 2020-02-21T23:29:30.364028Z 0 [Note] Failed to start slave threads for channel ''
Feb 22 07:29:30 mysql_02 mysqld[1459]: 2020-02-21T23:29:30.368845Z 0 [Note] Event Scheduler: Loaded 0 events
Feb 22 07:29:30 mysql_02 mysqld[1459]: 2020-02-21T23:29:30.369610Z 0 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Feb 22 07:29:30 mysql_02 mysqld[1459]: Version: '5.7.28'  socket: '/tmp/mysql.sock'  port: 3306  MySQL Community Server (GPL)

修改管理员密码

mysqladmin -uroot -p password 123456
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容