Mysql 8.0.12解压版安装
下载安装包
https://dev.mysql.com/downloads/mysql/
解压:
xz -d wyk/mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz
tar -xvf wyk/mysql-8.0.12-linux-glibc2.12-x86_64.tar -C /usr/local/
改文件夹名
mv mysql-8.0.12-linux-glibc2.12-x86_64 mysql
添加mysql用户&用户组
groupadd mysql
useradd -g mysql mysql
建数据文件夹
cd mysql
mkdir data
mkdir data/mysql
配置文件/etc/my.cnf
[client]
port=3306
default-character-set=utf8
socket=/usr/local/mysql/data/mysql.sock
[mysqld]
socket=/usr/local/mysql/data/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
# 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=/usr/local/mysql/log/error.log
pid-file=/usr/local/mysql/data/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
配置文件中修改了日志文件路径,需手动创建文件
mkdir log
touch error.log
授权
chown -R mysql:mysql mysql/
root账号初始化MYSQL
bin/mysqld --initialize --user=mysql
初始root密码在这里
添加mysql服务:
cp support-files/mysql.server /etc/init.d/mysql
启动mysql服务
service mysql start
关闭mysql服务
service mysql stop
添加开机启动服务
chkconfig --add mysql
添加环境变量
vim /etc/profile
export MYSQL_HOME=/usr/local/mysql
PATH=$MYSQL_HOME/bin:$PATH
source /etc/profile
如果启动服务或者进入mysql失败,可以删除data目录下的所有内容,然后检查/etc/my.cnf,然后重新初始化mysql。
修改mysql的root用户密码,root初始密码为在日志中上面有提到
进入数据库命令:mysql -u root –p
修改密码命令:SET PASSWORD = 'new password';
刷新权限命令:flush privileges;
查看数据库user表,注意mysql 5.8密码字段改为authentication_string。
命令:select host,user,authentication_string from user;
配置远程登录
修改远程登登录命令:update user set `Host` = '%' where `User` = 'root' limit 1;
然后刷新权限命令:flush privileges;
退出数据库
命令:quit;