MySQL8.0安装

2018-07-26 19:44  522人阅读  评论 (0)
Tags: mysql

1. linux二进制文件安装mysql8

创建mysql.cnf配置文件

[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock

下载安装包

mysql8下载地址 https://dev.mysql.com/downloads/mysql/

选择 Linux - GenericLinux - Generic (glibc 2.12) (x86, 64-bit) linux通用二进制文件

下载 Compressed TAR Archive 8.0.14 358.8M (mysql-8.0.14-linux-glibc2.12-x86_64.tar.xz) 下载tar.xz

添加用户

groupadd mysql
useradd -r -g mysql -s /bin/false mysql

切换目录

cd /usr/local

解压

tar -C /usr/local xJf /home/dotcoo/mysql-8.0.14-linux-glibc2.12-x86_64.tar.xz

软链接

ln -s mysql-8.0.14-linux-glibc2.12-x86_64 mysql

进入mysql目录

cd mysql

创建目录并修改权限

mkdir mysql-files
chmod 750 mysql-files
chown -R mysql .
chgrp -R mysql .

初始化mysql数据目录

bin/mysqld --initialize --user=mysql

ssl设置

bin/mysql_ssl_rsa_setup

再次修改权限

chown -R root .
chown -R mysql data mysql-files

添加service服务脚本

cp support-files/mysql.server /etc/init.d/mysql

添加systemd服务脚本

创建mysqld.service文件

vim /usr/lib/systemd/system/mysqld.service

文件内容

[Unit]
Description=MySQL Server
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

Type=notify

TimeoutSec=0

PermissionsStartOnly=true

#ExecStartPre=/usr/bin/mysqld_pre_systemd

ExecStart=/usr/local/mysql/bin/mysqld $MYSQLD_OPTS

#EnvironmentFile=-/etc/sysconfig/mysql

LimitNOFILE = 10000

Restart=on-failure

RestartPreventExitStatus=1

Environment=MYSQLD_PARENT_PID=1

PrivateTmp=false

重新加载服务列表

systemctl daemon-reload

启动mysql

service mysql start
/etc/init.d/mysql start
systemctl start mysqld
bin/mysqld_safe --user=mysql &

登录

bin/mysql -u root -p
# 密码在日志文件中

修改密码

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

2. centos yum安装mysql8

查看当前centos发行版本

cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

下载源rpm包

mysql8下载地址 https://dev.mysql.com/downloads/repo/yum/

下载 Red Hat Enterprise Linux 7 / Oracle Linux 7 (Architecture Independent), RPM Package (mysql80-community-release-el7-2.noarch.rpm) 下载rpm

安装源rpm包

yum localinstall -y mysql80-community-release-el7-2.noarch.rpm

安装mysql

yum install -y mysql-community-client.x86_64 mysql-community-common.x86_64 mysql-community-devel.x86_64 mysql-community-embedded-compat.x86_64 mysql-community-libs.x86_64 mysql-community-libs-compat.x86_64 mysql-community-server.x86_64 

启动mysql

systemctl start mysqld

查找密码

grep "temporary password" /var/log/mysqld.log

登录

bin/mysql -u root -p

修改密码

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

3. centos rpm安装mysql8

下载对应rpm包

下载地址: https://dev.mysql.com/downloads/mysql/

选择对应的系统和版本 下载bundle.tar包 解压即可

安装

yum install mysql-community-{server,client,common,libs}-*

4. ubuntu apt安装mysql8

替换源

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo vim /etc/apt/sources.list
:%s/archive.ubuntu.com/mirrors.163.com/g
sudo apt-get clean
sudo apt-get update

下载源deb包

mysql8下载地址 https://dev.mysql.com/downloads/repo/apt/

下载 Ubuntu / Debian (Architecture Independent), DEB Package (mysql-apt-config_0.8.12-1_all.deb) 下载deb

安装源deb包

sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb

更新

sudo apt-get update

安装mysql

sudo apt-get install -y mysql-server

启动mysql

sudo systemctl start mysql

查找密码

sudo cat /etc/mysql/debian.cnf

登录

bin/mysql -u debian-sys-maint -p

修改密码

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

登录

bin/mysql -u root -p

5. ubuntu deb安装mysql8

下载对应deb包

下载地址: https://dev.mysql.com/downloads/mysql/

选择对应的系统和版本 下载bundle.tar包 解压即可

安装

sudo apt-get install libaio1
sudo dpkg-preconfigure mysql-community-server_*.deb
sudo dpkg -i mysql-{common,community-client,client,community-server,server}_*.deb

6. windows安装mysql8

my.ini配置文件

[mysqld]
port=3306
basedir=C:/dotcoo/mysql
datadir=C:/dotcoo/mysql/data

初始化数据库

C:\dotcoo\mysql\bin\mysqld --defaults-file=C:\dotcoo\mysql\my.ini --initialize

启动数据库

C:\dotcoo\mysql\bin\mysqld --defaults-file=C:\dotcoo\mysql\my.ini

连接数据库

# 密码在日志文件中
mysql -u root -p

修改密码

alter user 'root'@'localhost' identified by '123456';
# select host, user, plugin, authentication_string from mysql.user;

安装为系统服务

C:\dotcoo\mysql\bin\mysqld --install-manual MySQL8 --defaults-file=C:\dotcoo\mysql\my.ini

7. 源码编译安装

参考地址: https://dev.mysql.com/doc/refman/8.0/en/source-installation.html

8. 重置密码

创建一个初始化文件

创建文件: C:\dotcoo\mysql\change_password.sql

在文件中添加修改密码语句:

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

使用init-file参数启动mysqld

C:\dotcoo\mysql\bin\mysqld --defaults-file=C:\dotcoo\mysql\my.ini --init-file=C:\dotcoo\mysql\change_password.sql

登录

启动成功后密码就修改为123456了

C:\dotcoo\mysql\bin\mysql -u root -p