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
复制
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进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
【专家有话说第五期】在不同年龄段,DBA应该怎样规划自己的职业发展?
墨天轮编辑部
1270次阅读
2025-03-13 11:40:53
MySQL8.0统计信息总结
闫建(Rock Yan)
482次阅读
2025-03-17 16:04:03
2月“墨力原创作者计划”获奖名单公布
墨天轮编辑部
453次阅读
2025-03-13 14:38:19
Ogg23ai高手必看-MySQL Innodb Cluster跟oracle的亲密接触
曹海峰
447次阅读
2025-03-04 21:56:13
SQL优化 - explain查看SQL执行计划(一)
金同学
387次阅读
2025-03-13 16:04:22
MySQL突然崩溃?教你用gdb解剖core文件,快速锁定“元凶”!
szrsu
333次阅读
2025-03-13 00:29:43
MySQL生产实战优化(利用Index skip scan优化性能提升257倍)
chengang
325次阅读
2025-03-17 10:36:40
一键装库脚本3分钟极速部署,传统耗时砍掉95%!
IT邦德
232次阅读
2025-03-10 07:58:44
MySQL数据库当前和历史事务分析
听见风的声音
228次阅读
2025-04-01 08:47:17
MySQL8.0直方图功能简介
Rock Yan
224次阅读
2025-03-21 15:30:53