Linux(ubuntu)二进制安装mysql8.0
mysql官方网站下载地址:https://dev.mysql.com/downloads/mysql/
1、创建mysql运行用户和组
groupadd -g 1001 mysql
useradd -g 1001 -u 1001 -s /sbin/nologin mysql
#创建用户和组时,gid和uid相同,便于权限管理
cd /usr/local/ #进入安装目录
tar xf mysql.... #解压
ln -s mysql-8.0.22-linux-glibc2.12-x86_64 mysql #创建链接文件
2、创建mysql数据存放目录,并授权给mysql用户
cd /usr/local/mysql #进入mysql目录
chown -R root.root * #授予root权限
mkdir /data/mysql #创建日志文件存放目录
chown mysql.mysql /data/mysql #授予mysql用户权限
3、 准备启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d #复制启动脚本到init.d目录下
vim /etc/init.d/mysql.server #找到"datadir="修改为以下内容
4、数据初始化
cd /usr/local/mysql/bin #进入到bin目录
mysqld --initialize --user mysql --datadir /data/mysql #进行初始化
mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory #出现这个报错安装libaio1包
apt -y install libaio1 #安装libaio1包
mysqld --initialize --user mysql --datadir /data/mysql #再次进行初始化
2021-04-09T00:03:05.180587Z 0 [System] [MY-013169] [Server] /usr/local/mysql-
8.0.22-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.22) initializing of server
in progress as process 1287
2021-04-09T00:03:05.185312Z 1 [System] [MY-013576] [InnoDB] InnoDB
initialization has started.
2021-04-09T00:03:05.523894Z 1 [System] [MY-013577] [InnoDB] InnoDB
initialization has ended.
2021-04-09T00:03:06.489253Z 6 [Note] [MY-010454] [Server] A temporary password
is generated for root@localhost: KLHp,b4_maQ= ##KLHp,b4_maQ= #标红这个是初始密码(一定要记下来)
5、环境变量
rz my.cnf #然后把my.cnf导入到/etc/下
mkdir /data/mysql/logs #创建日志存放目录
touch /data/mysql/logs/mysql-error.log #创建空日志文件
chown -R mysql.mysql logs/ #授予mysql用户权限
vim /etc/profile #添加环境变量,在最后添加下面这段内容
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile #加载环境变量
6、启动mysql服务
/etc/init.d/mysql.server start
7、登录mysql,并修改初始密码
mysql -u root -p'KLHp,b4_maQ=' #命令行进入mysql (-u为指定用户,-p为密码)
mysql> alter user user() identified by '123456'; #必须使用alter user修改
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
mysql -u root -p'123456' #退出测试成功
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
8、做开机自启动
vim /etc/rc.local #编写rc.local文件,添加以下内容
#!/bin/bash
/etc/init.d/mysql.server start
chmod +x /etc/rc.local #授予rc.local文件执行权限
systemctl start rc.local #启动rc.local
mysql8.0二进制安装完毕