Linux 上安装 Mysql 数据库

154 阅读1分钟

系统:centOS7

1. 下载 mysql 安装包

  • 下载地址
  • 安装下面流程,选择下载版本,最后一步点击鼠标右键“复制链接地址”

2. 服务器上下载 mysql 安装包

  • 使用 wget 安装
[root@iZj6c60her827uf9h1ihofZ ~]# wget https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
  • 安装 mysql-community-server
[root@iZj6c60her827uf9h1ihofZ ~]# rpm -ivh mysql80-community-release-el8-1.noarch.rpm
  • 更新数据源
[root@iZj6c60her827uf9h1ihofZ ~]# yum makecache
  • 安装
[root@iZj6c60her827uf9h1ihofZ ~]# yum install mysql-community-server
  • 如执行 yum install mysql-community-server 失败,先执行 yum module disable mysql
  • 查看是否安装成了,执行下列命令,如果出现下图则说明成功了
[root@iZj6c60her827uf9h1ihofZ ~]# cd /var/lib/
[root@iZj6c60her827uf9h1ihofZ lib]# ll

  • 初始化 mysql
[root@iZj6c60her827uf9h1ihofZ lib]# systemctl start mysqld
  • 查看是否安装成功了,出现下面内容,则说明成功了
[root@iZj6c60her827uf9h1ihofZ lib]# cd mysql
[root@iZj6c60her827uf9h1ihofZ mysql]# ll

3. 链接数据库

  • 查看密码
[root@iZj6c60her827uf9h1ihofZ mysql]# grep 'password' /var/log/mysqld.log

  • 连接 mysql,输入获得密码,出现 mysql> 则代表连接成功
[root@iZj6c60her827uf9h1ihofZ mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.22

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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> 

4. 修改密码

mysql> alter user root@localhost identified by '你的密码';