暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

记一次:centos7 安装mysql8

原创 chkl 2023-02-08
1479

1、首先,在网上下载:

mysql官网:https://dev.mysql.com/downloads/mysql/
下载mysql:

wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.32-linux-glibc2.12-x86_64.tar
复制

2.解压mysql包

tar -xvf ~/mysql-8.0.32-linux-glibc2.12-x86_64.tar
复制

再次解压

tar xvjf mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz
bzip2: (stdin) is not a bzip2 file.
tar: Child returned status 2
tar: Error is not recoverable: exiting now

tar -xvf mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz
ls -lh
total 1.6G
drwxr-xr-x  9 root root   129 Feb  8 17:53 mysql-8.0.32-linux-glibc2.12-x86_64
复制

建立软连接

ln -s mysql-8.0.32-linux-glibc2.12-x86_64 mysql
[root@localhost opt]# ls -lh
total 1.6G
lrwxrwxrwx  1 root root    35 Feb  8 18:04 mysql -> mysql-8.0.32-linux-glibc2.12-x86_64

复制

3.安装mysql

3.1创建mysql用户,组:
groupadd mysql
useradd -g mysql mysql
passwd mysql
复制
3.2 添加文件夹和所需文件
mkdir -p mysql/{data,run,log}
touch mysql/log/mysql-error.log
chown -R mysql:mysql mysql
[root@localhost opt]# tree mysql

复制
3.3 初始化mysql

如果无异常情况日志如下可以看到mysql默认会生成root账号和密码(–lower-case-table-names=1不区分表名大小写)

/opt/mysql/bin/mysqld --initialize --user=mysql --basedir=/opt/mysql/ --datadir=/opt/mysql/data/ --lower-case-table-names=1
复制

1675823972251.png

3.4 修改配置文件vim/etc/my.cnf
 [mysqld]
 port            = 3306
 socket          = /tmp/mysql.sock
 skip-external-locking
 skip-name-resolve
 pid-file = /opt/mysql/run/mysqld.pid
 datadir = /opt/mysql/data
 basedir = /opt/mysql
 log_error = /opt/mysql/log/mysql-error.log
复制
3.5 配置mysql服务,启动mysql
cp /opt/mysql/support-files/mysql.server /etc/init.d/mysqld
service mysqld  start
Starting MySQL.The server quit without updating PID file (/[FAILED]l/ru
复制
3.6配置全局环境变量
vi /etc/profile
PATH=/opt/mysql/bin:/optmysql/lib:$PATH
Source /etc/profile
复制

3.7 修改默认账户密码
mysql -uroot -p

输入安装时打印出的随机密码,登录

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root001';
复制
4.创建mysql用户

创建用户,授予权限:

CREATE USER 'username'@'ip.%' identified with mysql_native_password by 'passwd';
GRANT ALL PRIVILEGES ON db.* to 'username'@'ip.%' WITH GRANT OPTION;
flush privileges;
复制
:mysql忘记密码重置

免密码登陆,修改密码

vim /etc/my.cnf
在【mysqld】模块添加:skip-grant-tables
重启mysql服务: service mysqld restart
登陆mysql,mysql -u root -p //提示输入密码时直接敲回车选择mysql数据库
将root密码置空,update user set authentication_string = '' where user = 'root';
去掉my.cnf中的skip-grant-tables并重启mysql服务登陆mysql,修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';(注意,这里mysql默认加密用的sha,navicat连接会提示authentication plugin 'caching_sha2_password',可使用ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';)
复制
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论