当前位置: 首页 > news >正文

Linux(CentOS8)系统安装mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz

一、下载获取 mysql安装包;

MySQL :: Download MySQL Community Server (Archived Versions)

二、安装步骤

1、切换到安装目录下,并解压

tar -zxvf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz

2.移动解压后的文件并且重命名为mysql

 mv mysql-8.0.26-linux-glibc2.12-x86_64 /usr/local

 3.先切换至mysql文件夹下创建新文件夹data

cd /usr/local/mysql

 

4.创建mysql用户组和mysql用户

groupadd mysql

useradd -g mysql mysql 

 5.修改mysql目录权限

chown -R mysql.mysql /usr/local/mysql/

6.数据库初始化

注意事项:记录一下mysql数据库的临时密码*************,后面安装步骤是需要使用的!

./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize

 7.修改my.cnf文件

vi  /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命令,保存并退出 

8.创建mysql服务 

a)将mysql.server启动文件复制到/etc/init.d目录,使用cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld命令。

b)赋予权限,使用chmod +x /etc/rc.d/init.d/mysqld命令;

c)使用chkconfig --add mysqld创建mysql服务。

按照顺序执行!

cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld 
chkconfig --add mysqld 

9.配置环境变量 

vi /etc/profile

将下面配置添加到export 环境变量配置文件中

export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
export PATH

设置环境变量立即生效

source /etc/profile 

10.启动mysql服务

使用service mysql start命令;使用service mysql status命令,查看是否启动成功。 

[root ~]# service mysql start
Redirecting to /bin/systemctl start mysql.service
[root ~]# 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/VM-0-4-centos.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 VM-0-4-centos systemd[1]: Starting LSB: start and stop MySQL...
Jan 16 17:17:54 VM-0-4-centos mysqld[27231]: Starting MySQL.Logging to '/usr/local/mysql/data/VM-0-4-centos.err'.
Jan 16 17:17:55 VM-0-4-centos mysqld[27231]: SUCCESS!
Jan 16 17:17:55 VM-0-4-centos systemd[1]: Started LSB: start and stop MySQL. 

11.登陆mysql并且修改密码

这里输入的密码为 第 6 步初始化的默认密码

[root ~]# 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> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root123456';
Query OK, 0 rows affected (0.01 sec)
mysql> 

12.设置mysql远程登录后可使用客户端进行连接 

a)切换数据库,使用use mysql;命令。

b)修改mysql库中host值,使用update user set host='%' where user='root' limit 1;命令。

c)刷新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>


http://www.mrgr.cn/news/12100.html

相关文章:

  • fastapi知识点及应用
  • pyautogui的一些自动化示例,附代码
  • 计算机毕业设计选题推荐-OA办公管理系统-Java/Python项目实战
  • 金融涉案账户压降行动的实施成效与挑战
  • jenkins发送html邮件配置步骤与注意事项?
  • 认知杂谈25
  • SpringBoot -在Axis2中,RPCServiceClient调用WebService
  • Android PopupWindow弹窗动态显示在View的上下方,
  • 8月27日cs61c
  • Redis6.0新特性
  • 在我的博士科研生活中,SCI的英语写作一直是我的挑战。
  • Vue3+Ts封装input组件时遇到的问题
  • 【iOS端】基于Uniapp跨平台接入即构RTC+相芯美颜
  • APP封装安装配置参考说明
  • swift自定义数据集微调Qwen-7B大模型,转换模型后使用ollama跑起来
  • AutoGPT开源项目解读
  • Halcon20.11深度学习语义分割模型
  • 数据结构概念
  • 使用hutool实现http的调用
  • Java中IO基础文本数据处理:BufferedReader 和 BufferedWriter