mysql

1:安装前,我们可以检测系统是否自带安装 MySQL:
rpm -qa | grep mysql

2:安装 MySQL:
接下来我们在 Centos7 系统下使用 yum 命令安装 MySQL,需要注意的是 CentOS 7 版本中 MySQL数据库已从默认的程序列表中移除,所以在安装前我们需要先去官网下载 Yum 资源包,下载地址为:https://dev.mysql.com/downloads/repo/yum/
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum update
yum install mysql-server
注:如果配置了yum源,可使用yum install mysql-server命令一次性完成安装
然后我们可以通过输入 yum install -y mysql-server mysql mysql-devel 命令将mysql mysql-server mysql-devel都安装好(注意:安装mysql时我们并不是安装了mysql客户端就相当于安装好了mysql数据库了,我们还需要安装mysql-server服务端才行)

3:mysql服务的启动、停止、重启
service mysqld start|stop|restart
4:登录
[root@localhost ~]# mysql -h x.x.x.x -u root -p
Enter password:
退出:exit
5:设置mysql管理员root账号的密码
mysqladmin -u root password 123456
6:数据库管理命令
show databases; 查看服务器中当前有哪些数据库
use 数据库名; 选择所使用的数据库
create database 数据库名; 创建数据库
drop database 数据库名; 删除指定的数据库

mysql> show databases;
±-------------------+
| Database |
±-------------------+
| information_schema |
| mysql |
| test |
| yu |
±-------------------+
4 rows in set (0.00 sec)

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

7:数据表结构管理命令
create table 表名; 在当前数据库中创建数据表
show tables; 显示当前数据库中有哪些数据表
describe 表名; 显示当前数据表的结构

在学生数据库中创建一个名为test的课程表,test表包含两个字段id、name,均为非空字符串值,初始学号值设为20120000,其中,name字段被设为关键索引字段(PRIMARY KEY)
CREATE TABLE test (id CHAR(10) NOT NULL DEFAULT ‘20120000’,PRIMARY KEY (id),name CHAR(8)NOT NULL);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值