操作系统我们选择linux-generic, 然后选择x86_64安装包
-
安装包下载完后之后,将安装包解压
tar xvf mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz
-
解压完毕之后,我们将文件夹移动到 /usr/local下面, 然后建立软连接(符号链接或者说类似windows的快捷方式)
root@debian:~/soft# mv ./mysql-8.0.12-linux-glibc2.12-x86_64 /usr/local/ root@debian:~/soft# cd /usr/local/ root@debian:/usr/local# ls bin etc games include lib man mysql-8.0.12-linux-glibc2.12-x86_64 sbin share src root@debian:/usr/local# ln -s mysql-8.0.12-linux-glibc2.12-x86_64/ /usr/local/mysql root@debian:/usr/local# ls bin games lib mysql sbin src etc include man mysql-8.0.12-linux-glibc2.12-x86_64 share
-
安装步骤
-
创建mysql用户组
root@debian:/usr/local# groupadd mysql
-
创建mysql用户,并放入mysql用户组
root@debian:/usr/local# useradd -r -g mysql mysql
-
修改文件夹权限
将mysql下的文件所有者都改为rootchown -R root .
将mysql下的文件的用户组改为mysql
chgrp -R mysql .
最后文件权限如下
root@debian:/usr/local/mysql# ls -la total 340 drwxr-xr-x 10 root mysql 4096 Aug 17 17:58 . drwxrwsr-x 11 root staff 4096 Aug 17 16:59 .. drwxr-xr-x 2 root mysql 4096 Aug 17 16:46 bin drwxr-xr-x 2 root mysql 4096 Aug 17 16:46 docs drwxr-xr-x 3 root mysql 4096 Aug 17 16:45 include drwxr-xr-x 5 root mysql 4096 Aug 17 16:46 lib -rw-r--r-- 1 root mysql 301518 Jun 29 00:18 LICENSE drwxr-xr-x 4 root mysql 4096 Aug 17 16:45 man -rw-r--r-- 1 root mysql 687 Jun 29 00:18 README drwxr-xr-x 28 root mysql 4096 Aug 17 16:46 share drwxr-xr-x 2 root mysql 4096 Aug 17 16:46 support-files
-
初始化数据库
注意, 此操作之后,最后一行 会有一个初始化密码,用于root账号 的首次登陆root@debian:/usr/local/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
提示没有 libasio.so.1, 安装之(还缺少libnuma.so.1,一起安装)
apt-get install libaio1 apt-get install libnuma1
然后在试下初始化
root@debian:/usr/local/mysql# ./bin/mysqld --initialize --user=mysql 2018-08-17T10:13:54.738725Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.12-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.12) initializing of server in progress as process 15658 2018-08-17T10:13:57.502167Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: g3JLtaUwr4,n 2018-08-17T10:13:58.911266Z 0 [System] [MY-013170] [Server] /usr/local/mysql-8.0.12-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.12) initializing of server has completed
注意这行,这里给出了首次登陆的密码: g3JLtaUwr4,n
A temporary password is generated for root@localhost: g3JLtaUwr4,n
-
生成证书
./bin/mysql_ssl_rsa_setup
-
修改文件所有者,保证修改下如下
root@debian:/usr/local/mysql# ls -la total 344 drwxr-xr-x 11 root mysql 4096 Aug 17 18:13 . drwxrwsr-x 11 root staff 4096 Aug 17 16:59 .. drwxr-xr-x 2 root mysql 4096 Aug 17 16:46 bin drwxr-x--- 5 root mysql 4096 Aug 17 18:14 data drwxr-xr-x 2 root mysql 4096 Aug 17 16:46 docs drwxr-xr-x 3 root mysql 4096 Aug 17 16:45 include drwxr-xr-x 5 root mysql 4096 Aug 17 16:46 lib -rw-r--r-- 1 root mysql 301518 Jun 29 00:18 LICENSE drwxr-xr-x 4 root mysql 4096 Aug 17 16:45 man -rw-r--r-- 1 root mysql 687 Jun 29 00:18 README drwxr-xr-x 28 root mysql 4096 Aug 17 16:46 share drwxr-xr-x 2 root mysql 4096 Aug 17 16:46 support-files
-
启动数据库实例
root@debian:/usr/local/mysql# ./bin/mysqld_safe --user=mysql & [1] 15724 root@debian:/usr/local/mysql# Logging to '/usr/local/mysql/data/debian.err'. 2018-08-17T10:27:46.201422Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
新开一个连接终端,检查下mysql是否已经启动
root@debian:/usr/local/mysql# netstat -ano | grep 3306 tcp6 0 0 :::33060 :::* LISTEN off (0.00/0/0) tcp6 0 0 :::3306 :::* LISTEN off (0.00/0/0)
-
首次登录并且修改root密码
提示Enter password 的时候,输入上面生成的密码root@debian:/usr/local/mysql# cd /usr/local/mysql/bin root@debian:/usr/local/mysql/bin# ./mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.12 Copyright (c) 2000, 2018, 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. mysql>
修改密码, 假设我们修改为123456
mysql> set password = '123456'; Query OK, 0 rows affected (0.10 sec) mysql> alter user 'root'@'localhost' password expire never; Query OK, 0 rows affected (0.06 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql>
增加一个
root
@%
账号实现远程登录grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
或者用改表法
mysql> use mysql; Database changed mysql> update user set host = '%' where user = 'root'; Query OK, 1 row affected (0.05 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select host, user from user; +-----------+------------------+ | host | user | +-----------+------------------+ | % | root | | localhost | mysql.infoschema | | localhost | mysql.session | | localhost | mysql.sys | +-----------+------------------+ 4 rows in set (0.00 sec)
-
配置服务自动启动
- 复制服务文件到 /etc/init.d
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
- 启用mysqld.service
systemctl enable mysqld.service
如果不先执行该命令,会提示服务load失败
Failed to start mysqld.service: Unit mysqld.service failed to load: No such file or directory.
- 服务相关命令
- 服务状态:service mysqld status
- 服务启动:service mysqld start
- 服务停止:service mysqld stop
-
将mysql的二进制目录放入环境变量
打开文件 /etc/profile
在文件尾部加上export PATH=$PATH:/usr/local/mysql/bin
然后运行命令 source /etc/profile 以使环境变量马上生效
至此,就完成了mysql的安装和配置
-