Centos 7 linux 安裝MariaDB數據庫

一、yun安裝客戶端和服務端
 

yum install MariaDB-server MariaDB-client -y

二、配置

[root@miguvideo-2 /]# cat /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
#basedir=/tools/mysql
datadir=/data/mysql
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
socket=/var/lib/mysql/mysql.sock
#character config
character_set_server=utf8mb4
symbolic-links=0
#explicit_defaults_for_timestamp=true

三、啓動服務

# 啓動服務
systemctl  start  mariadb
# 停止服務
systemctl  stop  mariadb
# 重啓服務
systemctl  stop/restart/status  mariadb
# 查看服務狀態
systemctl  status  mariadb

四、驗證是否能使用

[root@miguvideo-2 /]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

mysql常用命令

 

desc  #查看錶結構
create database  #數據庫名
create table  #表名
查看如何創建db的
show create  database  #庫名
# 查看如何創建table結構的
show create table 表名;

# 修改mysql的密碼
set password = PASSWORD('redhat');

# 創建mysql的普通用戶,默認權限非常低
create user yining@'%' identified by 'yiningzhenshuai';

# 查詢mysql數據庫中的用戶信息
use mysql;
select host,user,password  from user;

 


給用戶添加權限命令

# 對所有庫和所有表授權所有權限
grant all privileges on *.* to 賬戶@主機名
# 給yining用戶授予所有權限
grant all privileges on *.* to yining@'%';  
# 刷新授權表
flush privileges; 


授予遠程登錄的權限命令(root不能遠程登錄的問題??)

 

# 給apollo用戶授予所有權限
grant all privileges on *.* to apollo@'%';
# 給與root權限授予遠程登錄的命令
# 'centos這是密碼隨意設置
grant all privileges on *.* to root@'%' identified by 'centos';  
# 此時可以在windows登錄linux的數據庫
# 連接服務器的mysql
mysql -uyining -p  -h  服務器的地址

 


學習mysql的數據備份與恢復

# 導出當前數據庫的所有db,到一個文件中
1.mysqldump -u root -p --all-databases > /data/AllMysql.dump
2.登錄mysql 導入數據
mysql -u root -p
> source /data/AllMysql.dump
3.通過命令導入數據
# 在登錄時候,導入數據文件,一樣可以寫入數據
mysql -uroot -p < /data/AllMysql.dump

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章