一、Linux(CentOS 7.4版)html
二、mysql-8.0.12-el7-x86_64.tar.gzmysql
参考:https://dev.mysql.com/doc/refman/8.0/en/installing.htmlsql
一、下载mysql解压版(mysql-8.0.12-el7-x86_64.tar.gz),下载地址http://dev.mysql.com/downloads/mysql/;数据库
二、解压mysql安装文件vim
命令:tar zxvf mysql-8.0.12-el7-x86_64.tar.gz安全
三、复制解压后的mysql到软件目录:服务器
命令:cp -r mysql-8.0.12-el7-x86_64 /data/soft/socket
四、添加系统mysql组和mysql用户:ide
命令:groupadd mysql工具
命令:useradd -r -g mysql -s /bin/false mysql
五、安装数据库
a、进入安装mysql软件目录:
命令: cd /data/soft/mysql-8.0.12-el7-x86_64
mysql目录结构
目录 | 目录的内容 |
---|---|
bin |
mysqld服务器,客户端和实用程序 |
docs |
信息格式的MySQL手册 |
man |
Unix手册页 |
include |
包含(标题)文件 |
lib |
图书馆 |
share |
用于数据库安装的错误消息,字典和SQL |
support-files |
其余支持文件 |
b、修改当前目录拥有者为mysql用户:
命令: chown -R mysql:mysql ./
c、配置mysql配置文件,命令:vim /etc/my.cnf
[client] port=3306 # 设置mysql客户端链接服务端时默认使用的端口 default-character-set=utf8 socket=/data/soft/mysql-8.0.12-el7-x86_64/data/mysql.sock [mysqld] basedir=/data/soft/mysql-8.0.12-el7-x86_64 # 设置mysql的安装目录 datadir=/data/soft/mysql-8.0.12-el7-x86_64/data socket=/data/soft/mysql-8.0.12-el7-x86_64/data/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/data/log/mysql-log/error.log pid-file=/data/soft/mysql-8.0.12-el7-x86_64/data/mysql.pid # # include all files from the config directory # !includedir /etc/my.cnf.d
d、建立日志文件(:wq保存退出,建立一个空文件便可),而且受权:
命令: vim /data/log/mysql-log/error.log
命令: chown mysql:mysql /data/log/mysql-log/error.log
e、初始化数据目录,包括mysql
包含初始MySQL受权表的 数据库,该表肯定如何容许用户链接到服务器
命令:bin/mysqld --initialize --user=mysql
若出现:./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
由于没有安装libaio
库,MySQL依赖于libaio
库,安装libaio
库
命令:yum search libaio
命令:yum install libaio
初始化数据库后,记录中出现了初始密码,没有初始密码能够去日志中查找,用户名:root,密码:!+Ejv-)lu0r>
f、若是您但愿服务器可以部署并自动支持安全链接,请使用 mysql_ssl_rsa_setup实用程序建立默认的SSL和RSA文件
命令:bin/mysql_ssl_rsa_setup
6.添加开机启动mysql服务和启动mysql服务
添加mysql服务
命令:cp support-files/mysql.server /etc/init.d/mysql
启动mysql服务
命令:service mysql start
关闭mysql服务
命令:service mysql stop
添加开机启动服务
命令:chkconfig --add mysql
七、添加mysql系统命令,修改系统文件,添加内容,是内容生效。
修改系统文件命令:vim /etc/profile
内容生效命令:source /etc/profile
8.修改mysql的root用户密码,root初始密码为在日志中上面有提到
a、进入数据库命令:mysql -u root -p
b、修改密码命令:alter user 'root'@'localhost' identified by 'newpassword';
c、刷新权限命令:flush privileges;
退出数据库,便可用root用户和新密码登陆数据库
d、退出数据库
命令:quit;
九、查看数据库user表,注意mysql 5.8密码字段改成authentication_string。
命令:select host,user,authentication_string from user;
十、配置远程登陆
修改远程登登陆命令:update user set `Host` = '%' where `User` = 'root' limit 1;
而后刷新权限命令:flush privileges;
完成以上步骤便可远程链接MySQL数据库了
十一、新增用户
命令:create user 'test'@'%' identified by '123456';
十二、给用户受权
命令:grant all privileges on *.* to test@'%' with grant option;
1三、若是是用navicat链接,因为mysql8的加密方式不一样,须要使用navicat的加密方式,修改密码
命令:alter user 'test'@'%' identified with mysql_native_password by '123456';