前言:MariaDB 和 MySQL是一家。MariaDB數據庫管理系統是MySQL的一個分支,主要由開源社區在維護,採用GPL授權許可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能輕鬆成爲MySQL的代替品。
這裏 安裝 MariaDB 來用用,使用ssh工具連接登錄上Linux
1、安裝
yum -y install mariadb-server
2、啓動
systemctl start mariadb #啓動服務
systemctl enable mariadb #設置開機啓動
systemctl restart mariadb #重新啓動
systemctl stop mariadb.service #停止MariaDB
3、登錄
輸入命令 mysql -uroot
,初次登錄root密碼爲空,不需要密碼,直接回車登錄到MariaDB
4、修改root密碼
MariaDB [(none)]> use mysql;
MariaDB [mysql]> update user set password=password("123456") where user='root';
MariaDB [mysql]> flush privileges;
退出,使用密碼重新登錄
MariaDB [mysql]> exit;
[root@mysvr ~]# mysql -uroot -p
輸入密碼123456
登錄成功,顯示如下信息,就可以愉快玩耍了。
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
5、忘記密碼登錄不上怎麼辦
- 修改MySQL的配置文件
vi /etc/my.cnf
- 在 [mysqld] 的段中加上一句 skip-grant-tables,保存退出
- 重啓mariadb服務
systemctl restart mariadb
- 執行上述 3、和 4、 步驟修改密碼
- 記得!重新編輯MySQL配置文件
vi /etc/my.cnf
把剛纔添加的skip-grant-tables刪掉!
6、修改數據庫字符集,使支持中文
要查看數據庫的原字符集設定可登錄mysql後,MariaDB [(none)]> show variables like ‘char%’;
- 修改配置文件
vi /etc/my.cnf
- 在 [mysqld] 的段中加上一句 character-set-server=utf8
- 重啓mariadb服務
systemctl restart mariadb
- 登錄MySQL,再執行
show variables like 'char%';
,可以看到字字符集爲utf8
其他
想要在本地連接服務器的數據庫,需要配置遠程連接數據庫權限
MySQL常用的命令學習
搞定