Mysql 8.0常规安装
1. MySQL安装准备
- 选择安装的MySQL版本
- 首先判断是否要和公司其他已经安装好的MySQL保持版本一致
- 如果没有上述要求,则一般会安装最新版本(目前是5.7)
- 如果不是实验新功能性质,则不要选择development release,而要安装General Availability (GA) release(代表稳定版本,可在生产系统用)
- 选择安装MySQL的方式
- 二进制安装包的方式(RPM,ZIP,Tar等)
- 源码方式(source code)
- 一般会选择二进制安装方式
- 如果有特殊需求,比如修改一部分源码或修改MySQL深层次的配置,则会选择源码
方式 - 我们以二进制Tar包安装方式为例
2. MySQL Linux 安装
- 1.下载正确的tar包
安装rz命令
yum install lrzsz
- 2.上传tar包到服务器并解压tar包到/usr/local/目录
cd /usr/local/
tar -xvf mysql-8.0.17-linux-glibc2.12-x86_64.tar
tar -xvf mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.17-linux-glibc2.12-x86_64 mysql
- 3.创建运行MySQL的用户和组(名字可以任意)
Shell> groupadd mysql
Shell> useradd mysql -g mysql
- 4.切换到mysql目录
Shell > mkdir /usr/local/mysql/data
- 5.修改解压包的权限
Shell> cd /usr/local/mysql
Shell> chown mysql:mysql data
- 6.安装MySQL
Shell> bin/mysqld --initialize --user=mysql --datadir /usr/local/mysql/data ##初始化数据目录
2019-10-12T02:46:14.688780Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.17) initializing of server in progress as process 2774
2019-10-12T02:46:20.508655Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: *i#XxXwi>4Qh ##密码
2019-10-12T02:46:23.080522Z 0 [System] [MY-013170] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.17) initializing of server has completed
shell> cp /support-files/mysql.server /etc/init.d/ ##将默认配置文件复制到指定目录
shell> bin/mysqld_safe --datadir=/usr/local/mysql/data --user=mysql & ##启动MySQL服务
shell> cp support-files/mysql.server /etc/init.d/mysql.server ##将MySQL加入到服务自启动
Shell> /etc/init.d/mysql.server start ##通过服务启动MySQL
[root@oracle12c support-files]# /etc/init.d/mysql.server start
Starting MySQL.Logging to '/usr/local/mysql/data/oracle12c.err'.
[ OK ]
- 启动过程中如果碰到如下错误
[root@localhost mysql]# bin/mysqld --initialize --user=mysql --datadir
/usr/local/mysql/data/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot openshared object file: No such file or directory
则需要安装包
yum install -y libaio
- 7修改密码
mysql> show databases;
报如下错误
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
alter user user() identified by 'mysql';
mysql 8.0之前可以通过set password=password('mysql');
修改密码
作者:若有所思11
链接:http://xiazai.dbbull.com/