Linux 安装 MySQL 8.0.26 超详细图文步骤
1、MySQL 8.0.26 下载
官方网站下载 MySQL 8.0.26 安装包,下载地址:
http://downloads.mysql.com/archives/community/
需要注意:Linux操作系统是32位还是64位,本案例采用Linux 64位操作系统进行讲解,通过wget命令下载安装包。
使用df -lh命令查看,磁盘大小,尽量安装在比较大的磁盘下,防止空间不够使用。
[[email protected] home]# df -lh Filesystem Size Used Avail Use% Mounted on devtmpfs 3.9G 0 3.9G 0% /dev tmpfs 3.9G 24K 3.9G 1% /dev/shm tmpfs 3.9G 604K 3.9G 1% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/vda1 50G 3.8G 44G 9% / tmpfs 783M 0 783M 0% /run/user/0
通过上述命令可以看出根目录空间比较充足,那么就把安装包下载到home目录了,执行wget命令。
[[email protected] home]# wget http://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
2、解压缩文件
解压 mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz 文件,使用tar -xvf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz 命令。
[[email protected] home]# tar -xvf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz mysql-8.0.26-linux-glibc2.12-x86_64/bin/ mysql-8.0.26-linux-glibc2.12-x86_64/bin/myisam_ftdump mysql-8.0.26-linux-glibc2.12-x86_64/bin/myisamchk mysql-8.0.26-linux-glibc2.12-x86_64/bin/myisamlog mysql-8.0.26-linux-glibc2.12-x86_64/bin/myisampack mysql-8.0.26-linux-glibc2.12-x86_64/bin/mysql .... mysql-8.0.26-linux-glibc2.12-x86_64/share/ mysql-8.0.26-linux-glibc2.12-x86_64/share/install_rewriter.sql mysql-8.0.26-linux-glibc2.12-x86_64/share/uninstall_rewriter.sql
3、移动文件
将压缩包移动到usr/local目录下,并重命名文件为mysql,使用mv /home/mysql-8.0.26-linux-glibc2.12-x86_64 /usr/local/mysql命令。
[[email protected] home]# mv mysql-8.0.26-linux-glibc2.12-x86_64 /usr/local/mysql [[email protected] home]# cd /usr/local/mysql/ [[email protected] mysql]# ls bin docs include lib LICENSE man README share support-files [[email protected] mysql]# cd .. [[email protected] local]# ls bin etc games include lib lib64 libexec mysql qcloud sbin share src yd.socket.server [[email protected] local]#
4、创建数据存放目录
在mysql根目录下新建一个目录data,主要用于存放数据库数据文件,使用mkdir data命令。
[[email protected] local]# cd mysql/ [[email protected] mysql]# mkdir data [[email protected] mysql]# ls bin data docs include lib LICENSE man README share support-files [[email protected] mysql]#
5、创建用户组和用户
创建mysql用户组和mysql用户,使用groupadd mysql和useradd -g mysql mysql命令。
[[email protected] mysql]# groupadd mysql [[email protected] mysql]# useradd -g mysql mysql
6、改变mysql目录权限
修改mysql目录权限,可以使用chown -R mysql.mysql /usr/local/mysql/命令。
修改mysql目录权限也可以通过chown -R mysql .和chgrp -R mysql .两个命令。注意:这两个命令都需要执行的,还有那个点不要忽视掉。
7、数据库初始化
数据库初始化./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize命令,得到临时密码。
[[email protected] mysql]# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize 2022-01-16T07:32:18.729960Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release. 2022-01-16T07:32:18.729960Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.26) initializing of server in progress as process 7691 2022-01-16T07:32:18.740975Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2022-01-16T07:32:19.800287Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2022-01-16T07:32:21.721672Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main 2022-01-16T07:32:21.722106Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main 2022-01-16T07:32:21.787669Z 6 [Note] [MY-010454] [Server] A temporary password is generated for [email protected]: j-6lA2aXv=Pz
需要注意:记录一下mysql数据库的临时密码 j-6lA2aXv=Pz,后面安装步骤是需要使用的,否则需要重新安装数据库或其他方式获取密码,此处问题省略。
8、修改my.cnf文件
修改my.cnf文件,使用vim /etc/my.cnf命令。
[mysqld] basedir = /usr/local/mysql datadir = /usr/local/mysql/data socket = /usr/local/mysql/mysql.sock character-set-server=utf8 port = 3306 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [client] socket = /usr/local/mysql/mysql.sock default-character-set=utf8 #[mysqld] #datadir=/var/lib/mysql #socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks #symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd #[mysqld_safe] #log-error=/var/log/mariadb/mariadb.log #pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # #!includedir /etc/my.cnf.d
直接将上述配置内容复制到my.cnf文件中,或者自行修改,然后执行:wq命令,保存并退出。
9、创建mysql服务
1)将mysql.server启动文件复制到/etc/init.d目录,使用cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld命令。
2)赋予权限,使用chmod +x /etc/rc.d/init.d/mysqld命令;
3)使用chkconfig --add mysqld创建mysql服务。
[[email protected] mysql]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [[email protected] mysql]# chmod +x /etc/rc.d/init.d/mysqld [[email protected] mysql]# chkconfig --add mysqld
检查mysql服务是否生效,使用chkconfig --list mysqld命令。
[[email protected] mysql]# chkconfig --list mysqld Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
10、配置全局环境变量
编辑/etc/profile文件,使用vim /etc/profile命令,在profile文件中添加如下两行配置,使用:wq命令保存后退出。
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib export PATH
设置环境变量立即生效使用source /etc/profile命令。
[[email protected] ~]# source /etc/profile [[email protected] ~]#
11、启动mysql服务
启动mysql服务,使用service mysql start命令;使用service mysql status命令,查看是否启动成功。
[[email protected] ~]# service mysql start Redirecting to /bin/systemctl start mysql.service [[email protected] ~]# service mysql status Redirecting to /bin/systemctl status mysql.service ● mysqld.service - LSB: start and stop MySQL Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled) Active: active (running) since Sun 2022-01-16 17:17:55 CST; 8s ago Docs: man:systemd-sysv-generator(8) Process: 27231 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS) CGroup: /system.slice/mysqld.service ├─27242 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/Java-JingXuan.pid └─27408 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=VM-0-4-cent... Jan 16 17:17:54 Java-JingXuan systemd[1]: Starting LSB: start and stop MySQL... Jan 16 17:17:54 Java-JingXuan mysqld[27231]: Starting MySQL.Logging to '/usr/local/mysql/data/Java-JingXuan.err'. Jan 16 17:17:55 Java-JingXuan mysqld[27231]: SUCCESS! Jan 16 17:17:55 Java-JingXuan systemd[1]: Started LSB: start and stop MySQL.
12、登录mysql修改密码
登录mysql数据库,使用mysql -uroot -p密码命令,临时密码是j-6lA2aXv=Pz。
[[email protected] ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 Server version: 8.0.26 Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
修改mysql临时密码,也就是将第七步数据库初始化生成的临时密码修改成自己需要设置的密码。
修改mysql数据库密码,使用ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';命令。
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'; Query OK, 0 rows affected (0.01 sec) mysql>
注意:此处123456修改为自己的需要密码即可。
13、设置mysql远程登录
1)切换数据库,使用use mysql;命令。
2)修改mysql库中host值,使用update user set host='%' where user='root' limit 1;命令。
3)刷新mysql权限,使用flush privileges;命令。
mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> update user set host='%' where user='root' limit 1; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql>
14、mysql客户端连接数据库
客户端连接mysql数据库,连接名(自定义名称)、主机(IP)、端口号及用户名和密码,点击测试连接按钮,显示连接成功即可。
注意:若提示无法连接,需要测试服务器3306端口是否开放。若服务器端可以通过查看防火墙情况,此时方式验证省略;而从客户端测试可以使用“telnet IP 端口号”命令。
更多其他软件安装配置步骤,如redis、kafka、fastdfs、elasticsearch等中间件安装配置图文步骤,公众号Java精选,回复中间件三个汉字,获取所有软件安装步骤。切勿乱回复,否则什么也没有!!!
- 我怀疑这些是 IDEA 造成 BUG 问题,但又找不到任何证据!
- Linux 安装 MySQL 8.0.26 超详细图文步骤
- 各大厂面试整理 20 道 Java 后端开发面试题总结
- GitHub 和 Gitee 开源免费 10 个超赞后台管理面板,看完惊呆了
- 【079期】面试官:设计一个安全的登录都要考虑哪些?我一脸懵逼。。
- 【077期】面试官问:谈谈你对 Java 线程安全与不安全的理解和看法?
- Spring Boot从入门到精通(十一)集成Swagger框架,实现自动生成接口文档
- 【072期】面试官:对并发熟悉吗?说说 wait、notify、yield 等线程间的协作
- 利用注解 反射优雅的实现通用 Excel 导入导出(通用版附源码)
- Spring Cloud 从入门到精通(二)集成 Nacos 构建微服务实现服务注册
- 【066期】面试官问:说一下 Java 反射机制有哪些应用场景?
- 2021年面试,整理全网初、中、高级常见Java面试题
- 关于 Session 会话深入探讨
- 史上最全面的 Lombok 注解介绍,Look 一下吧!
- Intellij IDEA 使用 Groovy 脚本一键生成带注解的实体类详细步骤