大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
系统环境: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 <
[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
启动成功!
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。