1. 程式人生 > >linux中mariadb基本用法詳解(企業級)

linux中mariadb基本用法詳解(企業級)

資料庫
表的每一個列名字的頭   叫做欄位
是高階的exel表格軟體

資料庫種類
sqlserver  sqllite  db2  
oracle  > mysql   比較多  


其中mysql  分支中有一個  mariadb

 

yum install mariadb-server -y
systemctl start mariadb

mysql_secure_installation
設定密碼

 mysql_secure_installation    ##資料庫安全初始化
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):         ##資料庫原始密碼(預設沒有直接回車)
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n]     ##是否要設定資料庫超級使用者密碼
New password:             ##輸入要設定的超級使用者密碼
Re-enter new password:         ##重複輸入
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]     ##是否刪除匿名使用者訪問許可權
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]         ##是否禁止超級使用者通過遠端登陸
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]     ##重新整理資料庫
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

 


mysql -uroot   -p
登陸


去掉埠
 netstat  -antlupe  |grep mysql


vim /etc/my.cnf.d
skip-networking=1


systemctl restart mariadb.service

就去掉了埠

 

資料庫管理

mysql  -uroot -p

> show databases;   (不區分大小寫)

> use  mysql;   進去庫  一定要用分號結尾

 

 

>show tables;  看到裡面的東西

 

 

> select * from user  檢視user庫中的所有東西

 

> select  Host,User,Password from user  選擇欄位檢視部分內容

 

> create database  westos;  建立庫

mysql -uroot -p

show databases  ;

use  westos ;

create  table  linux  (

   ->  username  varchar(10)  not null,    長度十個位元組不能為空

   -> password  varchar(50) not null

   ->  );

這樣就可以

desc linux;   查看錶的結構

insert  into  linux   values ('lee','123');

select * from linux 就可以看到了

 

 

這樣就可以插入資料了

 

修改

alter table linux rename userdata ;

 

將表linux改名為 userdata

表中繼續增加欄位

alter table linux  add  age  varchar(4);

 

預設在表中最後新增

alter table linux  drop age;

刪除 age 

alter table linux  add  age  varchar(4) after username ;

新增到  username  之後  不是最後一列

 

update linux set age='20' ;

都會改稱 20歲

 

updpate  linux set age='18' where username='lee' ;

updpate  linux set age='22' where username='lee'  and password='123';

增加限定條件地修改

 

刪除資料庫

delete  from linux  where username='westos';

從linux 中刪除  westos

drop  table  linux ;

刪除  表

drop  database westos;

刪除 庫

 

使用者授權

 

select User,Host   from mysql.user;

create  user  [email protected]'%'   表示可以遠端登陸

create  user  [email protected] identified

 

 

mysql -ulee -plee   帳號密碼登陸就可以測試了

 

show grants  for  [email protected];  檢視權力

grant  select  on westos.*  to  [email protected];

可以允許查詢westos庫中的所有的表