mysql(mariadb)

來源:互聯網
上載者:User

標籤:esc   server   alter   操作   ant   maria   添加   from   ima   

mysql(mariadb)

==========

 

yum install mariadb-server

 

mysqladmin -uroot -predhat password westos                   #修改本地mysql root密碼

mysqladmin -uroot -predhat -h 192.168.0.188 password westos          #修改遠程192.168.0.188 mysql伺服器 root密碼

 

mysql_secure_installation                             #第一次安裝mysql以後通過這條命令可以對mysql進行設定

 (配置)

 *******增刪改查*******

mysql -uroot -predhat               #從本機登入mysql資料庫

 

show databases;                 #顯示資料庫

 

 

 

 

use mysql;                     #進入資料庫

show tables;                   #顯示資料庫中的表

 

desc user;                    #查看user表的資料結構

 

flush privileges;                  #重新整理資料庫資訊

select host.user,password from user;       #查詢user表中的host,user,password欄位

 select * from mysql.user;              # 查詢mysql庫下的user表中的所有

 

 

create database westos;             #建立westos資料庫

 

use westos;

create table linux(                #建立表,username,password欄位

username varchar(15) not null,

               #字元長度     #不可為空白

password varchar(15) not null

);

 

 

insert into linux values (‘user1‘,‘passwd1‘);                     #在linux表中插入值為username = user1,password = password1

 

 

update linux set password=password(‘passwd2‘) where username=user1;       #更新linux表中user1 的密碼為password2 

 delete from linux where username=user1;                   #刪除linux表中user1的所以內容

 

ALTER TABLE linux ADD age  varchar(4)  BEFORE password  #在name欄位後添加欄位age

 

 

ALTER TABLE linux DROP age                       # 刪除age欄位

 

 

 

 

 

 *******使用者權限管理******

grant select on  *.* to [email protected] identified by ‘passwd1‘; 授權wesots 密碼為passwd1  #並且只能在本地 查詢資料庫的所以內容

 

 

REVOKE SELECT ON *.* from [email protected]

 

 

grant all on mysql.* to [email protected]‘%‘ identified by ‘passwd2‘; 授權user2 密碼為passwd2     #可以從遠程任意主機登入mysql 並且可以對mysql資料庫任意操作

 

 

********備份*******

/var/lib/mysql

mysqldump -uroot -predhat mysql > mysql.bak #備份mysql庫到mysql.bak

 

mysql -uroot -predhat westos < mysql.bak        #恢複mysql.bak 到westos庫

 

 

 

 *******mysql密碼恢複******

systemctl stop mariadb            #關閉mysql

 

mysqld_safe --skip-grant-tables &         #跳過grant-tables授權表  不需要認證登入本地mysql資料庫

 

 

update mysql.user set password=password(‘westos‘) where user=‘root‘;  

                        #更新mysql.user 表中條件為root使用者的密碼為加密westos

 

systemctl restart  mariadb            #重啟mysql 

 

mysql(mariadb)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.