欢迎投稿

今日深度:

数据库操作,

数据库操作,


1.安装mysql

查找于mariadb有关的软件包 yum search mariadb

安装mariadb yum install mariadb mariadb-server -y

2.启用mariadb

启用 systemctl start mariadb

开机自启 systemctl enable mariadb

3.设置mysql登陆密码

mysql_secure_installation

4.启动数据库

mysql -u用户名称 -p密码

例.

mysql -uroot -pwestos

5.mysql基本操作 注:每条语句后面都要跟分号

显示数据库,弹出一个目录,包含数据库名称

show databases;

使用名称为**的数据库

例.

use mysql;

显示数据库中的表

show tables;

显示表的结构

例.

desc user;

显示user表中的内容

select * from user;

显示表中的某几列

例.

select Host,User,Password from user;

创建以数据库名称为westos

create database westos;

在数据库中创建一表

create table westosuser(username varchar(10) not null,passwd varchar(6) not null);

向表中插入内容

insert into westosuser values(‘user1’,’123’);

按照指定顺序向表中插入数据

insert into westosuser(passwd,username) values(“456”,”user2”);

更新表中的内容

update westosuser set passwd=’456’ where username=”user1”;

添加sex列到westosuser表中

alter table westosuser add sex varchar(3);

删除表中用户名为user1的记录

delete from westosuser where username=”user1”;

删除表

drop table westosuser;

删除数据库

drop database westos;

6.用户和访问权限的操作

创建用户hello,可在本机登陆,密码为hello

create user hello@localhost identified by ‘hello’;

创建用户hello,可在远程登陆,密码为hello

create user hello@’%’ identified by ‘hello’;

给hello@localhost用户授权,如果为all,授权所有权限

grant all on mariadb.* to hello@localhost;

刷新,重载授权表

flush privileges;

查看用户授权

show grants for hello@localhost;

删除指定用户授权

revoke delete,update on mariadb.* from hello@localhost;

删除用户

drop user hello@localhost;

7.忘记mysql用户密码时的找回方法

关闭mariadb服务

systemctl stop mariadb

跳过授权表

mysqld_safe –skip-grant-table &

修改root密码

mysql

>update mysql.user set Password=password(‘westos’) where

User=’root’;

关闭跳过授权表的进程,启动mariadb服务,使用新密码即可

ps aux | grep mysql

kill -9 pid

mysql -uroot -p

8.mysql的备份与恢复

备份

mysqldump -uroot -p mariadb >mariadb.dump

mysqldump -uroot -pwestos –no-data mariadb > `date +%Y_%m_%

d`_mariadb.dump

mysqldump -uroot -pwestos –all-databases >mariadb4.dump

恢复

mysqladmin -uroot -pwestos create mariadb2

mysql -uroot -pwestos mariadb2< mariadb.dump

www.htsjk.Com true http://www.htsjk.com/mariadb/24823.html NewsArticle 数据库操作, 1.安装mysql 查找于mariadb有关的软件包 yum search mariadb 安装mariadb yum install mariadb mariadb-server -y 2.启用mariadb 启用 systemctl start mariadb 开机自启 systemctl enable mariadb 3.设置mysql登陆...
相关文章
    暂无相关文章
评论暂时关闭