mysql安装教程

tech2025-05-01  3

删除原生mariadb

rpm -qa | grep mariadb mariadb-libs-5.5.56-2.el7.x86_64 yum remove mariadb-libs-5.5.56-2.el7.x86_64 rpm -e mariadb-libs-5.5.56-2.el7.x86_64

安装包

可以去官网下载

mysql-community-libs-8.0.20-1.el7.x86_64.rpm mysql-community-client-8.0.20-1.el7.x86_64.rpm mysql-community-server-8.0.20-1.el7.x86_64.rpm

安装mysql

将rpm包放在/opt/app/mysql目录下,执行以下命令:

[root@t24nalagw01kf mysql]<20200601 18:28:34># rpm -ivh mysql-community-libs-8.0.20-1.el7.x86_64.rpm warning: mysql-community-libs-8.0.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-libs-8.0.20-1.el7################################# [100%] [root@t24nalagw01kf mysql]<20200601 18:28:47># rpm -qa | grep mysql-community-libs mysql-community-libs-8.0.20-1.el7.x86_64 [root@t24nalagw01kf mysql]<20200601 18:28:52># rpm -ivh mysql-community-client-8.0.20-1.el7.x86_64.rpm warning: mysql-community-client-8.0.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-client-8.0.20-1.e################################# [100%] [root@t24nalagw01kf mysql]<20200601 18:29:14># rpm -ivh mysql-community-server-8.0.20-1.el7.x86_64.rpm warning: mysql-community-server-8.0.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-server-8.0.20-1.e################## ( 54%) ################################# [100%] [root@t24nalagw01kf mysql]<20200601 18:31:15>#

启动mysqld

service start mysqld

查看初始密码

初始密码为:B1HT.kRa=yhn

[root@t24nalagw01kf log]<20200601 19:24:28># cat /var/log/mysqld.log 2020-06-01T10:57:58.630784Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.20) initializing of server in progress as process 99116 2020-06-01T10:57:58.645198Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2020-06-01T10:57:59.821083Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2020-06-01T10:58:02.690122Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: B1HT.kRa=yhn 2020-06-01T10:58:07.167606Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.20) starting as process 99363 2020-06-01T10:58:07.183159Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2020-06-01T10:58:07.600339Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2020-06-01T10:58:07.762161Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060 2020-06-01T10:58:08.005741Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. 2020-06-01T10:58:08.041679Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.20' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL.

登录mysql

mysql -u root -p

修改初始密码

ALTER USER root@localhost IDENTIFIED BY 'Qzmp123!@#';

新建用户

CREATE USER hammer@% IDENTIFIED BY 'Qzmp123!@#'; CREATE USER 'sampadm'@'localhost' IDENTIFIED BY 'Qzmp123!@#'; create database sampdb; grant all on sampdb.* to 'sampadm'@'localhost';

新建数据库

CREATE DATABASE ham_message;

用户授权

grant all privileges on ham_message.* to hammer@'%';

指令

\g 命令结束,go的意思。 \G 命令结束,垂直显示结果。 ; 命令结束。

函数

now() user() version()

显示当前系统时间 登录用户 服务器版本

mysql> select now(), user(), version(); +---------------------+----------------+-----------+ | now() | user() | version() | +---------------------+----------------+-----------+ | 2020-07-23 17:29:14 | root@localhost | 8.0.20 | +---------------------+----------------+-----------+ 1 row in set (0.00 sec)

database()

检索默认数据库

mysql> select database(); +------------+ | database() | +------------+ | NULL | +------------+ 1 row in set (0.00 sec) mysql> use sampdb; Database changed mysql> select database(); +------------+ | database() | +------------+ | sampdb | +------------+ 1 row in set (0.00 sec) mysql -u sampadm -p sampdb mysql> select database(); +------------+ | database() | +------------+ | sampdb | +------------+ 1 row in set (0.00 sec)

美史联盟表

prisident表

字段约束描述姓名

describe 命令

describe student ‘sex’;

学生表

create table student( name varchar(20) not null, sex enum('F', 'M') not null, student_id int unsigned not null auto_increment, primary key (student_id) ) engine = InnoDB; create table grade_event ( date date not null, category enum('T', 'Q') not null, event_id int unsigned not null auto_increment, primary key(event_id) ) engine = InnoDB;
最新回复(0)