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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • LNMP Web服务搭建 mysql与php安装 1、JAVA Web环境(企业更多) [tomcat(jvm)]...
    高博666阅读 3,717评论 0 0
  • 安装并配置MySQL数据库 3.2.1安装MySQL数据库 1.MySQL数据库的安装环境准备 如果读者没有物理服...
    SkTj阅读 9,512评论 0 6
  • 一、项目目标 搭建一个高可用web集群网站 二、项目规划 2.1 ip地址规划 2.2 拓扑图 2.3 相关说明 ...
    夏日之光阅读 9,541评论 0 1
  • 前后左右都是人,腾挪闪避的空间很少,对方有备而来,链甲对于拳头脚尖凳子腿的防御力都不错。坚持战斗到最后一刻的老约翰...
    帅气的小恒阅读 1,930评论 0 2
  • 二月的风筝 驮着缕缕清风 呢喃的鸟语 衔来春的温馨 风筝飞来了 睁大春的眼睛 儿童追寻着 白云上面的梦 偶尔的滑落...
    挥之易阅读 1,144评论 0 0