温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

MySQL预编译包安装配置

发布时间:2020-06-23 04:43:41 来源:网络 阅读:478 作者:丁广鹏 栏目:MySQL数据库

系统环境:CentOS 7.6
关闭防火墙等安全机制
检查系统有没有默认安装的数据库
[root@mysqlmaster ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64

卸载掉默认数据库
[root@mysqlmaster ~]# rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps

下载预编译二进制包
[root@mysqlmaster ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

解压包
[root@mysqlmaster ~]# tar fx mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /usr/local

给mysql重命名 或者创建软连接
[root@mysqlmaster ~]# mv /usr/local/mysql-5.7.18-linux-glibc2.5-x86_64/ /usr/local/mysql

创建软连接 (如果重命名了就不用创建软连接了)
[root@mysqlmaster ~]# ln -s /usr/local/mysql-5.7.18-linux-glibc2.5-x86_64/ /usr/local/mysql

创建用户和组
[root@mysqlmaster ~]# groupadd mysql
[root@mysqlmaster ~]# useradd -r -g mysql mysql

给mysql写个配置文件
[root@mysqlmaster ~]# vim /etc/my.cnf

[mysqld]
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
symbolic-links=0

[mysqld_safe]
log-error=/usr/local/mysql/logs/error.log
pid-file=/usr/local/mysql/mysql.pid

[client]
socket=/usr/local/mysql/mysql.sock

配置文件写好后紧接着创建配置文件里提到的路径
[root@mysqlmaster ~]# mkdir -p /usr/local/mysql/data
[root@mysqlmaster ~]# mkdir -p /usr/local/mysql/logs
[root@mysqlmaster ~]# touch /usr/local/mysql/logs/error.log

授权
[root@mysqlmaster ~]# chown -R mysql.mysql /usr/local/mysql/
[root@mysqlmaster ~]# chown -R mysql.mysql /etc/my.cnf

安装
[root@mysqlmaster ~]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

额外做一下安全加固
[root@mysqlmaster ~]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

copy启动脚本
[root@mysqlmaster ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

修改文件
[root@mysqlmaster ~]# sed -i '46c basedir=/usr/local/mysql' /etc/init.d/mysqld
[root@mysqlmaster ~]# sed -i '47c datadir=/usr/local/mysql/data' /etc/init.d/mysqld
[root@mysqlmaster ~]# sed -i '63c mysql_pid_file_path=/usr/local/mysql/data/mysqld.pid' /etc/init.d/mysqld

启动数据库
[root@mysqlmaster ~]# /etc/init.d/mysqld start
启动数据库成功!

设置软连接方便启动
[root@mysqlmaster ~]# ln -s /usr/local/mysql/bin/* /usr/local/sbin/

修改密码(五交互式高大上修改密码),并登录成功!
[root@mysqlmaster ~]# mysql -e "use mysql;alter user 'root'@'localhost' identified by '123456';"
[root@mysqlmaster ~]# mysql -uroot -p123456

加入到systemctl 进行管理
cat > /usr/lib/systemd/system/mysqld.service <<EOF
[mysqld]
[Unit]
Description=MySQL
SourcePath=/etc/init.d/mysqld
Before=shutdown.target

[Service]
User=mysql
Type=forking
ExecStart=/etc/init.d/mysqld start
ExecStop=/etc/init.d/mysqld stop

[Install]
WantedBy=multi-user.target
EOF

重新加载服务的配置文件,并重启mysqld
systemctl daemon-reload
systemctl restart mysqld

查看日志是否启动成功
[root@mysqlmaster ~]# journalctl -f
启动成功!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI