mysql的安装,yum安装
关闭CentOS8中MYSQL默认的mysql仓库
[root@localhost ~]# dnf remove @mysql
CentOS Stream 8 - AppStream 4.5 MB/s | 6.7 MB 00:01
CentOS Stream 8 - BaseOS 1.6 MB/s | 2.3 MB 00:01
CentOS Stream 8 - Extras 13 kB/s | 9.3 kB 00:00
无法匹配参数 mysql 中的配置档案
依赖关系解决。
无需任何处理。
完毕!
[root@localhost ~]# dnf module reset mysql && sudo dnf module disable mysql
需要更改配置文件
[root@localhost ~]#vi /etc/yum.repos.d/mysql-community.repo
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/8/$basearch/
enabled=1
gpgcheck=0
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/8/$basearch/
enabled=1
gpgcheck=0
[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/8/$basearch/
enabled=1
gpgcheck=0
配置完成之后就开始安装mysql5.7的版本
[root@localhost ~]# dnf --enablerepo=mysql57-community install mysql-community-server
已安装:
mysql-community-client-5.7.34-1.el7.x86_64
mysql-community-common-5.7.34-1.el7.x86_64
mysql-community-libs-5.7.34-1.el7.x86_64
mysql-community-server-5.7.34-1.el7.x86_64
ncurses-compat-libs-6.1-7.20180224.el8.x86_64
安装完后之后就需要开启服务
获取初始密码
用于后面的配置,修改密码等
[root@localhost ~]# systemctl enable --now mysqld.service
[root@localhost ~]# grep 'A temporary password' /var/log/mysqld.log |tail -1
2021-04-28T10:49:46.398090Z 1 [Note] A temporary password is generated for root@localhost: hVSQha8jHZ+N
[root@localhost ~]# mysql_secure_installation
[root@localhost ~]# sudo mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
The existing password for the user account root has expired. Please set a new password.
New password:
Re-enter new password:
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : yes
New password:
Re-enter new password:
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : yes
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : yes
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : no //要不要禁用root远程连接
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : yes
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : yes
Success.
All done!
看到这个all done!就表明配置好了,选项也弄好了
数据库的操作
[root@localhost ~]# mysql -u root -pZHANGde12+Jun
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.34 MySQL Community Server (GPL)
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> show databases; //查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> CREATE DATABASE zdj; //创建一个zdj数据库
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| zdj |
+--------------------+
5 rows in set (0.00 sec)
mysql> use zdj //进入zdj数据库
Database changed
mysql> CREATE TABLE lang(id int not null,name varchar(50) null,age tinyint); //创建了一个名为lang的表
Query OK, 0 rows affected (0.01 sec)
mysql> show tables;
+---------------+
| Tables_in_zdj |
+---------------+
| lang |
+---------------+
1 row in set (0.00 sec)
删除数据库和表
mysql> DROP TABLE lang; //删除lang这个表
Query OK, 0 rows affected (0.00 sec)
mysql> show tables;
Empty set (0.00 sec)
mysql> show databases; //查看数据库有zdj这个数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| zdj |
+--------------------+
5 rows in set (0.00 sec)
mysql> drop databases zdj; //删除zdj这个数据库
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'databases zdj' at line 1
mysql> drop database zdj;
Query OK, 0 rows affected (0.00 sec)
mysql> show databases; /再查看,没有zdj这个数据库了
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)