一、下载mysql8.0安装包
官网下载地址:https://dev.mysql.com/downloads/mysql/
二、安装mysql
1、将已经下载好的mysql上传到 /usr/local/software ,解压:
[root@localhost software]# tar -xvf mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz
2、创建mysql系统用户组和系统用户
groupadd mysql useradd -r -g mysql mysql
使用此命令出现报错解决方法:
#groupadd mysql
#useradd -r -g mysql mysq
查看用户组:#groups mysql
3、创建数据目录
在此位置下:/usr/local/software/mysql-8.0.23-linux-glibc2.12-x86_64
mkdir datatmp chmod 777 ./data./tmp
新建修改相关的配置文件
cd support-files touch my-default.cnf vim my-default.cnf #如果命令未成功,可以在support-files文件夹下直接创建
然后将如下内容些人文件:
[mysqld]
basedir = /usr/local/software/mysql-8.0.23-linux-glibc2.12-x86_64
datadir = /usr/local/software/mysql-8.0.23-linux-glibc2.12-x86_64/data
port = 3306
socket = /usr/local/software/mysql-8.0.23-linux-glibc2.12-x86_64/tmp/mysql.sock
lower_case_table_names=1 #其中lower_case_table_names=1 表示忽略大小写敏感
[client]
default-character-set=utf8
socket= /usr/local/software/mysql-8.0.23-linux-glibc2.12-x86_64/tmp/mysql.sock
[mysql]
default-character-set=utf8
socket= /usr/local/software/mysql-8.0.23-linux-glibc2.12-x86_64/tmp/mysql.sock
4、修改当前目录为mysql用户
chown -R mysql:mysql ./
初始化Mysql配置表: 切换至目录:/usr/local/software/mysql-8.0.23-linux-glibc2.12-x86_64
bin/mysqld --initialize --user=/usr/local/software/mysql-8.0.23-linux-glibc2.12-x86_64 --datadir=/usr/local/software/mysql-8.0.23-linux-glibc2.12-x86_64/data
最后面显示Mysql的密码:Oj;kRMt5UIlo
2021-03-05T00:52:28.722816Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Oj;kRMt5UIlo
如果执行失败,需要删除data 和tmp文件下所有内容,检查配置后重新执行初始化。
5、设置开机启动服务
[root@localhost ~]# cd /usr/local/software/mysql-8.0.23-linux-glibc2.12-x86_64/support-files/ #进入support-files文件夹
cpmysql.server /etc/init.d/mysql
chmod+x /etc/init.d/mysql
chkconfig--add mysql
chkconfig--list mysql (检查是否启动成功)
6、手动启动服务
vim /etc/profile (配置环境变量)
export PATH=$PATH:/usr/local/tools/mysql-8.0.21/bin:/usr/local/tools/mysql-8.0.21/lib
service mysql start (start,stop,restart命令)
source /etc/profile
启动报错:mysql: error while loading shared libraries: libtinfo.so.5: cannot open share
[root@localhost ~]# mysql -uroot -p
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
解决方法:
sudo ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5
7、登录mysql重置密码
mysql -uroot -pOj;kRMt5UIlo #密码是步骤4中生成的
alter user'root'@'localhost'identifiedby'root'; #重置密码为root
flush privileges;
8、设置远程连接
注:前提是防火墙关闭或端口放行
mysql->use mysql;
mysql->update user set host = '%' where user ='root';
mysql->flush privileges;
mysql->select 'host' from user where user='root';
9、
网友评论