centos7搭建mysql
yum install -y mysql
或
yum install mariadb-server mariadb
启动数据库
systemctl start mariadb #启动MariaDB
systemctl stop mariadb #停止MariaDB
systemctl restart mariadb #重启MariaDB
systemctl enable mariadb #设置开机启动
连接数据库
格式: mysql -h主机地址 -u用户名 -p用户密码
刚创建的mysql在本机上登录可以免密码
# mysql
创建数据库
命令:create database <数据库名>;
例:create database testdb;
给数据库分配用户
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON testdb.testtable TO testusername@localhost IDENTIFIED BY 'newpassword';
SET PASSWORD FOR 'testusername'@'localhost' = OLD_PASSWORD('newpassword');
删除数据库
命令:drop database <数据库名>;
例:drop database testdb;
切换数据库
命令: use <数据库名>
创建数据表
命令:create table <表名> ( <字段名1> <类型1> [,..<字段名n> <类型n>]);
例:create table MyClass(id int(4) not null primary key auto_increment,name char(20) not null,sex int(4) not null default '0',degree double(16,2));
删除数据表
命令:drop table <表名>
修改表数据
语法:update 表名 set 字段=新值,… where 条件
mysql> update MyClass set name='Mary' where id=1;
其他命令请参考
Mysql命令大全
MySQL 数据类型
https://www.runoob.com/mysql/mysql-data-types.html
网友评论