重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
系统环境:CentOS 7.6
关闭防火墙等安全机制
检查系统有没有默认安装的数据库
[root@MySQLmaster ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
创新互联建站主要从事网站设计、网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务丰县,10年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18980820575
卸载掉默认数据库
[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 <
[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
启动成功!