Mysql环境部署
创始人
2024-11-13 02:04:58
0

一、centos7 中安装 mysql 8.x

1、下载安装包

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.33-1.el7.x86_64.rpm-bundle.tar

2、解压

tar -zxvf mysql-8.0.33-1.el7.x86_64.rpm-bundle.tar

3、卸载mariodb

yum remove -y *mariadb*

4、依次安装依赖包(libs,client,common,server)

yum -y install mysql-community-common-8.0.33-1.el7.x86_64.rpm

yum install mysql-community-client-8.0.33-1.el7.x86_64.rpm 
yum install mysql-community-libs-8.0.33-1.el7.x86_64.rpm

yum install -y mysql-community-server-8.0.33-1.el7.x86_64.rpm

5、初始化配置mysqlh

vim /etc/my.cnf

[mysqld]
explicit_defaults_for_timestamp=tree

mysqld -initialize

6、启动mysql服务

systemctl start mysqld

systemctl enable mysqld      #开机启动mysql服务

7、获得初始密码

cat /var/log/mysqld.log|grep password

8、初始密码登陆

mysql -uroot -p Zhang@2002

9、设置密码

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Zhang@2002';

二、数据库操作

1、数据库对象
2、数据库的操作
1.数据库系统         DBMS
2.数据库         DB
3.表         table
4.记录         record
5.字段         feild
(1)查看数据库

select host,user from mysql,user;

show databases;

(2)创建库

mysql> create datababse test charset utf8;
Query OK, 1 row affected, 1 warning (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
5 rows in set (0.00 sec)

(3)查看库

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

3、表的操作
(1)选择表

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

(2)查看表

mysql> show tables;
+------------------------------------------------------+
| Tables_in_mysql |
+------------------------------------------------------+
| columns_priv |
| component |
| db |
| default_roles |
| engine_cost |
| func |
| general_log |
| global_grants |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| password_history |
| plugin |
| procs_priv |
| proxies_priv |
| replication_asynchronous_connection_failover |
| replication_asynchronous_connection_failover_managed |
| replication_group_configuration_version |
| replication_group_member_actions |
| role_edges |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+------------------------------------------------------+
38 rows in set (0.01 sec)

(3)创建表

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';
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| user           |
| user0          |
+----------------+

(4)删除表

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)

       

新增列

ALTER TABLE `test`.`user`
ADD COLUMN `realname` VARCHAR(45) NULL AFTER `password`;
mysql> desc user;
+----------+-------------+------+-----+---------+---------
-------+
| Field | Type | Null | Key | Default | Extra
|
+----------+-------------+------+-----+---------+---------
-------+
| id | int | NO | PRI | NULL |
auto_increment |
| username | varchar(45) | NO | UNI | NULL |
|
| password | varchar(45) | NO | | NULL |
|
| realname | varchar(45) | YES | | NULL |
|
+----------+-------------+------+-----+---------+---------
-------+
4 rows in set (0.01 sec)

        修改列名

mysql> ALTER TABLE `test`.`user`
-> CHANGE COLUMN `realname` `zsxm` VARCHAR(45) NULL
DEFAULT NULL ;
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc user;
+----------+-------------+------+-----+---------+---------
-------+
| Field | Type | Null | Key | Default | Extra
|
+----------+-------------+------+-----+---------+---------
-------+
| id | int | NO | PRI | NULL |
auto_increment |
| username | varchar(45) | NO | UNI | NULL |
|
| password | varchar(45) | NO | | NULL |
|
| zsxm | varchar(45) | YES | | NULL |
|
+----------+-------------+------+-----+---------+---------
-------+

        删除列

mysql> ALTER TABLE `test`.`user`
-> DROP COLUMN `zsxm`;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc user;
+----------+-------------+------+-----+---------+---------
-------+
| Field | Type | Null | Key | Default | Extra
|
+----------+-------------+------+-----+---------+---------
-------+
| id | int | NO | PRI | NULL |
auto_increment |
| username | varchar(45) | NO | UNI | NULL |
|
| password | varchar(45) | NO | | NULL |
|
+----------+-------------+------+-----+---------+---------
-------+
3 rows in set (0.00 sec)

4、记录的操作
(1)新增
insert into 表名(字段名列表) values (字段值列表)

(2)删除
delete from user where 条件

(3)修改


zhangsan的密码修改为123


 

相关内容

热门资讯

秒懂教程!微信群链接拼三张房卡... 拼三张是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:56001354许多玩家在游戏中会购买房卡来享...
秒懂教程“微信斗牛房间怎么弄,... 微信斗牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:86909166许多玩家在游戏中会购买房卡来...
仕邦出勤安卓系统,高效便捷的考... 你有没有听说最近仕邦出勤安卓系统的新变化?这可是个大新闻,让我来给你详细说说,保证让你对这款系统有了...
秒懂教程!微信牛牛房卡如何充值... 牛牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:71319951许多玩家在游戏中会购买房卡来享受...
房卡必备教程“金花大厅链接房卡... 人皇大厅是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:15984933许多玩家在游戏中会购买房卡来...
秒懂教程!微信炸金花怎么买房卡... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:66336574许多玩家在游戏中会购买房卡来享...
一分钟了解“在哪里买炸金花房卡... 新毛豆互娱是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:86909166许多玩家在游戏中会购买房卡...
秒懂教程!微信里面拼三张房卡在... 拼三张是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:56001354许多玩家在游戏中会购买房卡来享...
给大家讲解“微信链接金花房卡怎... 随意玩是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:160470940许多玩家在游戏中会购买房卡来...
秒懂教程!微信斗牛房卡找谁买,... 斗牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:71319951许多玩家在游戏中会购买房卡来享受...
ia实测“怎样创建微信金花链接... 金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:44346008许多玩家在游戏中会购买房卡来享受...
秒懂教程!微信上链接牛牛房卡,... 牛牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:66336574许多玩家在游戏中会购买房卡来享受...
安卓平板带学习系统的,智能教育... 你有没有想过,拥有一款既能满足日常娱乐需求,又能助力学习的安卓平板电脑,是不是就像拥有了双重身份的超...
一分钟推荐“微信炸金花链接怎样... 微信炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:44346008许多玩家在游戏中会购买房卡...
秒懂教程!拼三张房卡链接去哪里... 拼三张是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:56001354许多玩家在游戏中会购买房卡来享...
一分钟推荐“金花链接房卡如何充... 九酷大厅是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:86909166许多玩家在游戏中会购买房卡来...
秒懂教程!炸金花房卡怎么弄,新... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:71319951许多玩家在游戏中会购买房卡来享...
房卡必备教程“微信牛牛房卡招代... 牛牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:160470940许多玩家在游戏中会购买房卡来享...
秒懂教程!怎么创建牛牛房间房卡... 斗牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:66336574许多玩家在游戏中会购买房卡来享受...
安卓手机用锤子系统,探索个性化... 你有没有发现,现在安卓手机的世界里,锤子系统可是个热门话题呢!它就像一股清新的风,吹进了这个五彩斑斓...