安装 mysql 8-yum

Operating System: Alibaba Cloud Linux 3 (Soaring Falcon)

Arch: x86_64

mysql-8.0.32

---

 

序章

再安装一次 MySQL,这次是在 类CentOS 的 Alibaba Cloud Linux 3 系统上进行,使用 yum 安装。

 

安装步骤

说明,全程使用 root 账号安装(存在风险)。

 

yum 搜索

# yum search mysql

Last metadata expiration check: 0:17:11 ago on Mon 18 Mar 2024 10:01:02 AM CST.
=============================================================================== Name & Summary Matched: mysql ===============================================================================
mysql.x86_64 : MySQL client programs and shared libraries
MySQL-zrm.noarch : MySQL backup manager
anope-mysql.x86_64 : MariaDB/MySQL modules for Anope IRC services

……省略……

mysql-common.x86_64 : The shared files required for MySQL server and client
mysql-devel.x86_64 : Files for development of MySQL applications
mysql-errmsg.x86_64 : The error messages files required by MySQL server
mysql-libs.x86_64 : The shared libraries required for MySQL clients
mysql-mmm.noarch : Multi-Master Replication Manager for MySQL
mysql-selinux.noarch : SELinux policy modules for MySQL and MariaDB packages
mysql-server.x86_64 : The MySQL server and related files
mysql-test.x86_64 : The test suite distributed with MySQL

……省略……

查看信息:

# yum info mysql-common.x86_64

Last metadata expiration check: 0:35:47 ago on Mon 18 Mar 2024 10:01:02 AM CST.
Available Packages
Name         : mysql-common
Version      : 8.0.32
Release      : 1.0.2.al8
Architecture : x86_64
Size         : 137 k
Source       : mysql-8.0.32-1.0.2.al8.src.rpm
Repository   : alinux3-updates
Summary      : The shared files required for MySQL server and client
URL          : http://www.mysql.com
License      : GPLv2 with exceptions and LGPLv2 and BSD
Description  : The mysql-common package provides the essential shared files for any
             : MySQL program. You will need to install this package to use any other
             : MySQL package.

# yum info mysql-server.x86_64
Last metadata expiration check: 0:36:05 ago on Mon 18 Mar 2024 10:01:02 AM CST.
Available Packages
Name         : mysql-server
Version      : 8.0.32
Release      : 1.0.2.al8
Architecture : x86_64
Size         : 32 M
Source       : mysql-8.0.32-1.0.2.al8.src.rpm
Repository   : alinux3-updates
Summary      : The MySQL server and related files
URL          : http://www.mysql.com
License      : GPLv2 with exceptions and LGPLv2 and BSD
Description  : MySQL is a multi-user, multi-threaded SQL database server. MySQL is a
             : client/server implementation consisting of a server daemon (mysqld)
             : and many different client programs and libraries. This package contains
             : the MySQL server and some accompanying files and directories.

# yum info mysql.x86_64
Last metadata expiration check: 0:36:24 ago on Mon 18 Mar 2024 10:01:02 AM CST.
Available Packages
Name         : mysql
Version      : 8.0.32
Release      : 1.0.2.al8
Architecture : x86_64
Size         : 15 M
Source       : mysql-8.0.32-1.0.2.al8.src.rpm
Repository   : alinux3-updates
Summary      : MySQL client programs and shared libraries
URL          : http://www.mysql.com
License      : GPLv2 with exceptions and LGPLv2 and BSD
Description  : MySQL is a multi-user, multi-threaded SQL database server. MySQL is a
             : client/server implementation consisting of a server daemon (mysqld)
             : and many different client programs and libraries. The base package
             : contains the standard MySQL client programs and generic MySQL files.

ben发布于博客园

执行安装

# yum install mysql-server

Last metadata expiration check: 0:40:37 ago on Mon 18 Mar 2024 10:01:02 AM CST.
Dependencies resolved.

……省略……

Installed:
  libaio-0.3.112-1.2.al8.x86_64        mariadb-connector-c-config-3.2.6-1.al8.noarch mecab-0.996-2.al8.x86_64          mysql-8.0.32-1.0.2.al8.x86_64 mysql-common-8.0.32-1.0.2.al8.x86_64
  mysql-errmsg-8.0.32-1.0.2.al8.x86_64 mysql-server-8.0.32-1.0.2.al8.x86_64          protobuf-lite-3.5.0-15.al8.x86_64

Complete!

安装完成。

 

启动服务

安装后检查服务状态:

# systemctl status mysql
Unit mysql.service could not be found.
[root@hostname nginx]# systemctl status mysqld
● mysqld.service - MySQL 8.0 database server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: enabled)
   Active: inactive (dead)

默认开机启动。

安装后,未启动。

启动服务:

# systemctl start mysqld.service

成功。

再次查看服务状态:

# systemctl status mysqld.service
● mysqld.service - MySQL 8.0 database server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2024-03-18 10:59:16 CST; 28s ago

……省略……

Mar 18 10:59:09 hostname systemd[1]: Starting MySQL 8.0 database server...
Mar 18 10:59:09 hostname mysql-prepare-db-dir[260036]: Initializing MySQL database
Mar 18 10:59:16 hostname systemd[1]: Started MySQL 8.0 database server.

已启动。

查看 mysql 进程:

# ps -ef | grep mysql
mysql     260116       1  2 10:59 ?        00:00:01 /usr/libexec/mysqld --basedir=/usr

只有一个。

ben发布于博客园

验证服务器

安装后,可以使用 mysql 的 root 用户(root@localhost) 访问,默认 不需要密码

默认端口 3306。

# mysql -uroot 

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 8.0.32 Source distribution

Copyright (c) 2000, 2023, 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>

查看 默认数据库,有 4个。

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

用户表 user 在 mysql 数据库中。

mysql> desc mysql.user;

查看 mysql.user 表的用户基本信息:

mysql> select user,host,authentication_string,plugin from mysql.user;

注意,这里的 dev@localhost 账号是 后面自己添加的,不是系统默认的。

 

注意,可以给 没有密码的 root 用户添加密码的。

 

mysql相关命令的位置

mysql

# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

# ls /usr/bin | grep mysql
mysql
mysqladmin
mysqlbinlog
mysqlcheck
mysql_config_editor
mysqld_pre_systemd
mysqldump
mysqldumpslow
mysqlimport
mysql_migrate_keyring
mysqlpump
mysql_secure_installation
mysqlshow
mysqlslap
mysql_ssl_rsa_setup
mysql_tzinfo_to_sql
mysql_upgrade

ben发布于博客园

mysqld

服务器命令(ps -ef 中可见)。

# whereis mysqld
mysqld: /usr/sbin/mysqld /usr/libexec/mysqld /usr/share/man/man8/mysqld.8.gz

# ls /usr/sbin | grep mysql
mysqld

# ls /usr/libexec | grep mysql
mysql-check-socket
mysql-check-upgrade
mysqld
mysql-prepare-db-dir
mysql-scripts-common
mysql-wait-stop

 

服务器配置

配置文件位于:/etc/my.cnf.d 目录下(/etc/my.cnf 指向这里)。

# cat ../my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

# pwd
/etc/my.cnf.d

my.cnf.d]# ls
client.cnf  mysql-default-authentication-plugin.cnf  mysql-server.cnf

mysql-server.cnf 文件内容(默认)

 

执行 服务器配置 修改:

/etc/my.cnf.d/ mysql-server.cnf 添加下面的内容:

# 端口

port=33306

# 默认字符集
character_set_server=utf8mb4

说明,utf8mb4 支持 emoji 表情等,真正的 utf8。ben发布于博客园

 

修改服务器后,重启mysql:

# systemctl restart mysqld.service

成功。

ben发布于博客园

创建 mysql 用户及授权

针对 本文的 mysql version 8。

执行:创建

mysql> create user 'dev'@'%' identified by 'password';
Query OK, 0 rows affected (0.01 sec)

没有授权的 用户,登录后 只能看到 2个数据库:

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| performance_schema |
+--------------------+
2 rows in set (0.00 sec)

查看此时的权限

mysql> show grants for 'dev'@'%';
+---------------------------------+
| Grants for dev@%                |
+---------------------------------+
| GRANT USAGE ON *.* TO `dev`@`%` |
+---------------------------------+
1 row in set (0.00 sec)

 

执行:授权

mysql> grant all privileges on *.* to 'dev'@'%';
Query OK, 0 rows affected (0.01 sec)

授予了所有权限。

注意,存在风险,真实情况应该根据需要授权。权限名称 可以参考 mysql.user 表 的 以“_priv” 几位的字段名。

ben发布于博客园

新用户登录

# mysql -udev -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 8.0.32 Source distribution

Copyright (c) 2000, 2023, 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>

成功。

ben发布于博客园

本文涉及命令

  1. yum search mysql
  2. yum info mysql-common.x86_64
  3. yum install mysql-server
  4. systemctl status mysql
  5. systemctl start mysqld.service
  6. mysql -uroot 
  7. show databases;
  8. desc mysql.user;
  9. whereis mysql
  10. systemctl restart mysqld.service
  11. select user,host,authentication_string,plugin from mysql.user;
  12. create user 'dev'@'%' identified by 'password';
  13. grant all privileges on *.* to 'dev'@'%';
  14. mysql -uroot
  15. msyql -udev -p
  16.  

 

 

---END---

ben发布于博客园

本文链接:

https://www.cnblogs.com/luo630/p/18080234

ben发布于博客园

参考资料

1、

 

ben发布于博客园

ben发布于博客园

 

posted @ 2024-03-29 21:25  快乐的总统95  阅读(326)  评论(0编辑  收藏  举报