1官网下载安装包
2解压及安装依赖
tar -xvf mysql-8.0.33-1.el7.x86_64.rpm-bundle.tar
rpm -ivh mysql-community-common-8.0.33-1.el7.x86_64.rpm
rmp -ivh mysql-community-client-plugins-8.0.33-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.33-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.33-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.33-1.el7.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.0.33-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.33-1.el7.x86_64.rpm
3初始化,开启服务
systemctl start mysqld
4查看初始密码,登录mysql
cd /var/log
grep -n password mysqld.log
mysql -u root -p
操作
1删除库
mysql> drop database test;
Query OK, 0 rows affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
2创建库
mysql> create datababse test charset utf8;
Query OK, 1 row affected, 1 warning (0.01 sec)
mysql> show databases;
|
3查看库
show databases;
4选择库
use mysql;
5查看表
show tables;
6创建表
mysql> CREATE TABLE `test`.`user` (
-> `id` INT NOT NULL AUTO_INCREMENT,
-> `username` VARCHAR(45) NOT NULL,
-> `password` VARCHAR(45) NOT NULL,
-> PRIMARY KEY (`id`),
-> UNIQUE INDEX `username_UNIQUE` (`username` ASC)
VISIBLE)
-> COMMENT = 'us';
7删除表
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| user |
| user0 |
+----------------+
2 rows in set (0.00 sec)
mysql> drop table user0;
Query OK, 0 rows affected (0.01 sec)
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| user |
+----------------+
1 row in set (0.01 sec)
8新增列
ALTER TABLE `test`.`user`
ADD COLUMN `realname` VARCHAR(45) NULL AFTER `password`;
9删除列
mysql> ALTER TABLE `test`.`user` DROP COLUMN `zsxm`;