mysql 1104 access to database_mariadb数据库

##配置网络

vim/etc/sysconfig/network-scripts/ifcfg-eth0 写网络配置文件

systemctl restart network  重启网络

##配置yum源

vim /etc/yum.repos.d/rhel_dvd.repo 写yum源配置文件

yum clean all     重置yum源

##修改服务器名字

hostnamectl set-hostnamemariadb.westos.com 更改本地服务器名字

hostname 查看本地本地服务器名字

85cd01243cf9fb040a9b47212c693d3b.png

f9d571da8cd41984ce2cf09f404065f1.png

f2ada69f7531a06af696f03a5eaa10c0.png

####### mariadb数据库########### 数据库厂商 mysql  oracle一 数据库的安装与配置

1 yum install mariadb-server -y  ##安装mariadb

cc533c25607bf1308b69895708cd6e9d.png

2 systemctl start mariadb       ##开启mariadb服务

3 mysql                          ###进入mysql数据库

4 netstat -antlpe | grep mysql   ###查询mysqul

5 vim /etc/my.cnf              ###mysqul的配置文件

skip-networking=1

e0dc710e29230d68f34a4af139007a92.png

6 systemctl restart mariadb    ###重启mariadb服务

7 netstat -antlpe | grep mysqul

8 mysql

9 mysql_secure_installation   ###mysql安全内容配置

(1)Enter current password for root(enter for none):[Enter]

(2)Set root password? [Y/n]Y

New password:                ###输入新密码

Re-enter new password:       ###确认密码

(3)Remove anonymous users? [Y/n]Y

(4)Disallow root login remotely?[Y/n] Y

(5)Remove test database and accessto it? [Y/n] Y

(6)Reload privilege tables now?[Y/n] Y

10 mysql -uroot -p

11 mysql

图:

9c3bdcd6df96c26186b29675f4b8b020.png

58bc51236ca484d6b1b1ed9eb134ecbe.png

d5f6998ade0c5d2ca0f22286197cade3.png

c2ad468f707d5f40eeab49efe85049b0.png

二  数据库基本语句

1 登陆

(1)mysql -uroot -pqwer1234  ##qwer1234是密码

(2)mysql -uroot -p

Enter password:             ##密码不显示;安全性能高

2 查询

(1)show databases;             ###显示数据库

(2)use mysql                  ###进入mysql库

(3)show tables;                ###显示当前库中表的名字

(4)select * from user          ###查询user表中的所有内容(* 可以用表中所有字段来代替)

(5)desc user;                  ###查询表的结构 (显示所有字段的名称)

ec2fc4e4b105eb0798e4951dd26606b8.png

e5114b8594371f1ed6f02fe9be1c6dcf.png

5dedf08d7b0c69c462e15438d6fc7805.png

e1fbda0d769ee8d7fc0babcee7705851.png

3 数据库及表的建立

(1)create database westos;  ####创建westos库

show databases;         ###显示数据库

9a0d9992378a0656044794e28bba64af.png

(2)use westos               ###进入westos库

create table linux(      ####linux表

-> username varchar(15) not null,

-> password varchar(15) not null); ###表中含有username,password两个字段;字符长度最大为15个,都不为空。(字符长度可根据需要更改)

desc linux;               ###查询表的结构 (显示所有字段的名称)

2eeabce3fadfa2fbe1da4a33ecb9c8fa.png

(3)insert into linux values ('user','123');###向表中插入数据,

select * from linux;      ###查询linux表中的所有内容

insert into linux values('user1',password('123') );

      ###向表中插入数据,加密密码a6d96ca22518368f4bc2f4fbc1acf8c3.png

4 更新数据库信息

(1)update linux set password=('234') where username='user1';

##### 更新user1的密码

select * from linux;  ###查询linux表中的所有内容

f253f61fca043a3611611e782ad5d563.png

(2)update linux set password=password('123') where  username='user';

#####更新use的密码,并加密

select * from linux;

827d1ae391798730a9472939450c1987.png

(3)alter table linux add age varchar(4);

####增加age字段到表的最后一列

select * from linux;

97dd5705d1864c3e0426d4032d9ac36a.png

(4)alter table linux add exam varchar(4) after password;

####增加exam字段到指定位置

select * from linux;

a41e3da0619dcca4d844ff01521f9026.png

(5)alter table linux drop exam; ####删除linux中的exam字段

select * from linux;

58b151eb318ce152cbb6623fbc96b1c2.png

(6)update linux set password=password('123')where ( username='user' or username='user1');

####更新两个用户的密码,并加密

     select * from linux; 97e7df6e06771017cdda556d66bad976.png

5 数据库的备份

2 mysqldump -u root -pqwer1234 --all-database

####备份所有表中的所有数据

3 mysqldump -u root -pqwer1234 --all-database --no-data

####备份所有表,但不备份数据

4 mysqldump -u root -pqwer1234 westos

####备份westos库

5 mysqldump -u root -pqwer1234 westos > /mnt/westos.sql

####备份westos库并把数据保存到/mnt/westos.sql

8 mysql -uroot -pqwer1234 -e "create database westos;"

####建立westos库

9 mysql -u root -pqwer1234 westos < /mnt/westos.sql

####把数据导入westos库

10 mysql -u root -pqwer1234

16 mysqldump -u root -pqwer1234 westos linux > /mnt/linux.sql

####备份westos库中的linux表并把数据保存到/mnt/linux.sql

17 mysqldump -u root -pqwer1234 westos test> /mnt/test.sql

####备份westos库中的test表并把数据保存到/mnt/test.sql

27 mysql -u root -pqwer1234 -e "show tables from westos"

###显示westos库中表的名字

28 mysql -u root -pqwer1234 westos < /mnt/test.sql

####把test表中数据导入westos库

29 mysql -u root -pqwer1234 -e "show tables from westos"

###显示westos库中表的名字

8ae84b96736bfe0908eba78d686a7219.png

71f7df8282fecec4195764bfda862030.png

b2f5217d9c8fe7d749f55050dec3a67d.png

6 数据库的删除

(1) 删除表中数据  delete from linux where username='username';

mysql -u root -pqwer1234

MariaDB [(none)]> usewestos    ###进入westos库

MariaDB [westos]> select * fromlinux;    ###查询linux表中的所有内容

delete from linux whereusername='user1'; ###删除linux表中的user1的数据

delete from linux whereusername='user'; ###删除linux表中的user的数据

select * from linux; ###查询linux表中的所有内容

b9cce52251d5f97a33942a0d608b2490.png

(2)删除表

drop table linux;

(3)删除库

drop database westos;

5072f954c132bce381a6540979fca825.png

24cf5afb36f374d7b2b2a26046fc2615.png

7 用户授权

(1)建立用户

MariaDB [(none)]> create userlee@localhost identified by ' lee';

####建立用户lee本机登陆

MariaDB [(none)]> create userlee@'%' identified by ' lee';

####建立lee用户,网络登陆

f9995da90f3e9cce6d13eae6fe5b26ab.png

c6025eef9699cfa1b58e53cc097cd2bb.png

(2)用户授权

MariaDB [(none)]> grantinsert,update,delete,select on westos.test to lee@localhost;

### 本机登陆lee,授权

MariaDB [(none)]> grant selecton westos.* to lee@'%' ;

####网络登陆lee,授权

a3aa04b62d5778a2e7247f4f89e35854.png

(3)查看用户权力

MariaDB [(none)]> show grantsfor lee@'%'

####查看用户权力

MariaDB[(none)] > show grantsfor lee@localhost;、

####查看用户权力

(4)去除用户授权权力

MariaDB [(none)]> revoke deleteon westos.test from lee@localhost;

######去除用户授权权力

MariaDB [(none)]> show grantsfor lee@localhost; 查看权限

397b603f14c179d16c7cafc85e82c6e4.png

(5)删除用户

MariaDB [(none)]> selectUser,Host from mysql.user;查看用户

MariaDB [(none)]]> drop userlee@'%'; 删除用户

         MariaDB [(none)]> selectUser,Host from mysql.user;查看用户bba42b7a70a4e353dcd6bcab49c97861.png

8  密码修改(1)超级用户密码知道

mysqladmin -uroot -p234 password lee   ##修改超级用户密码为lee

(2)超级用户密码忘记

[root@mariadb mnt]# mysqld_safe--skip-grant-tables &

####开启mysql登陆接口并忽略授权表

[root@mariadb mnt]# mysql ###进入mysql

MariaDB [(none)]> selectUser,Host,Password from mysql.user;

####查看mysql.user中用户及用户密码

MariaDB [(none)]> updatemysql.user set Password=password('234') where User='root';  ##更新超级用户密码信息为234

MariaDB [(none)]> select User,Host,Passwordfrom mysql.user;

####查看mysql.user中用户及用户密码

MariaDB [(none)]> quit

[root@mariadb mnt]# fg

[root@mariadb mnt]# killall -9 mysqld_safe ####关闭mysqld_safe进程

[root@mariadb mnt]# ps aux | grep mysql ###过滤mysql的所有进程

[root@mariadb mnt]# kill -9 mysqlpid    ####关闭mysql的所有进程

[root@mariadb mnt]# systemctl restart mariadb ###重启mariadb服务

[root@mariadb mnt]# mysql -uroot -p234 ###登陆测试

796e560739512c5f5eb967410f2ebf15.png

c88f977e39097da5ab1a87d302b359af.png

5b74982291a53704bae5f7c12fa5dee3.png

f014520ebce10207fad8676a172b7387.png

三 数据库的页管理工具

1.安装

156 yum install httpd php php-mysql -y ##安装 httpd php php-mysql三个安装包

yum install php-mysql.x86_64-y

yum install httpd -y

yum install php.x86_64 -y

157 systemctl start httpd.service              ##开启httpd服务

158 systemctl enable httpd

159 systemctl stop firewalld.service              ##关闭火墙

160 systemctl disable firewalld

2. 需要下载

162 phpMyAdmin-3.4.0-all-languages.tar.bz2 #### 压缩包

163 tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2 -C /var/www/html

####解压压缩包到/var/www/html

164 mv phpMyAdmin-3.4.0-all-languages/ mysqladmin

#### 将安装包下的所有文件移动到 mysqladmin

165 cd mysqladmin

166 cp -p  config.sample.inc.phpconfig.inc.php ###复制配置文件

167 vim config.inc.php   ###写配置文件

$cfg['blowfish_secret'] = 'mysql';/* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

d6727ace05c338c361dba3f3c8a550d7.png

168 systemctl restart httpd

3.测试

访问

173 http://172.25.254.144/mysqladmin

d7e6d27820893823073ac30ae01901ff.png

41f8a262131ffde2eaa245497676488c.png

004b4a78eeab1f9c730b6c2bd7905b4d.png

399c75d0b407163be872028fae11233a.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值