MySQL下载地址

一、下载

http://mirrors.163.com/mysql/Downloads/MySQL-5.7/

二、创建用户

[root@web02 ~]# useradd mysql -s /sbin/nologin -M
[root@web02 ~]# id mysql
uid=1002(mysql) gid=1002(mysql) 组=1002(mysql)

三、解压、移动、创建软连接

[root@web02 /server/tools]# tar xf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@web02 /server/tools]# mv mysql-5.7.26-linux-glibc2.12-x86_64 /application/mysql-5.7.26
ln -s /application/mysql-5.7.26/ /application/mysql

四、删除mariadb

rpm -e --nodeps mariadb-libs

五、创建配置文件

[root@web02 /server/tools]# vim /etc/my.cnf

[mysqld]
basedir = /application/mysql/
datadir = /application/mysql/data
socket = /tmp/mysql.sock
server_id = 1
port = 3306
log_error = /application/mysql/data/oldboy_mysql.err
[mysql]
socket = /tmp/mysql.sock
prompt = zhangweibin [\d]>

六、检查mariadb是否已卸载,安装libaio-devel,创建数据目录/data

[root@web02 /server/tools]# rpm -qa mariadb-libs
[root@web02 /server/tools]# yum install libaio-devel -y
mkdir -p /application/mysql/data
chown -R mysql.mysql /application/mysql/

七、初始化数据库

/application/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/application/mysql/ --datadir=/application/mysql/data

八、配置MySQL服务

[root@web02 /application/mysql/support-files]# vim /etc/systemd/system/mysqld.service

[Unit]
Description=MySQL Server by zhangweibin
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=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

九、启动MySQL、设置开机自启

[root@web02 /application/mysql/support-files]# systemctl start mysqld
[root@web02 /application/mysql/support-files]# systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /etc/systemd/system/mysqld.service.
[root@web02 /application/mysql/support-files]# systemctl status mysqld

十、查看MySQL端口

[root@web02 /application/mysql/support-files]# netstat -lntup|grep mysql
tcp6 0 0 :::3306 :::* LISTEN 7285/mysqld
[root@web02 /application/mysql/support-files]# ps -ef|grep mysql|grep -v grep
mysql 7285 1 0 09:41 ? 00:00:00 /application/mysql/bin/mysqld --defaults-file=/etc/my.cnf

十一、配置环境变量登录

[root@web02 /application/mysql/support-files]# echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
[root@web02 /application/mysql/support-files]# tail -1 /etc/profile
export PATH=/application/mysql/bin:$PATH
[root@web02 /application/mysql/support-files]# . /etc/profile
[root@web02 /application/mysql/support-files]# echo $PATH
/application/mysql/bin:/application/nginx/sbin:/application/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

十二、登录MySQL

[root@web02 /application/mysql/support-files]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
zhangweibin [(none)]>quit

十三、设置MySQL密码

mysqladmin -u root password '123456'

十四、交互式登录MySQL数据库

mysql -uroot -p

十五、如果出错就看错误日志:

日志文件 cat /application/mysql/data/zhangweibin_mysql.err

create database wordpress;
use wordpress;
grant all privileges on wordpress.* to wordpress@'172.16.1.%' identified by '123456';
flush privileges;
select user,authentication_string,host from mysql.user;
quit

你可能感兴趣的:(MySQL下载地址)