1、先安装mariadb数据库
sudo apt-get install mariadb-server mariadb-client
2、查看mysql版本和运行状态
查看版本
mysql --version
输出类似以下:
mysql Ver 15.1 Distrib 10.1.29-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
查看服务运行状态
sudo service mysql status
输出类似以下:
● mariadb.service - MariaDB database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset:
Active: activating (start) since Sat 2018-08-04 18:53:56 CST; 4s ago
Process: 13651 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VA
Process: 13648 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_STAR
Process: 13647 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/r
Main PID: 13741 (mysqld)
Tasks: 26 (limit: 4915)
CGroup: /system.slice/mariadb.service
└─13741 /usr/sbin/mysqld
8月 04 18:53:56 xxxxxxx systemd[1]: Starting MariaDB database s
8月 04 18:53:57 xxxxxxx mysqld[13741]: 2018-08-04 18:53:57 1404
3、后台运行
sudo service mysql start 开启
sudo service mysql stop 关闭
sudo service mysql restart 重起
或
sudo service mariadb start 开启
sudo service mariadb stop 关闭
sudo service mariadb restart 重起
或
sudo service mariadb-server start 开启
sudo service mariadb-server stop 关闭
sudo service mariadb-server restart 重起
4、登录测试
mysql -u root
登录成功,类似如下
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.1.29-MariaDB-6 Ubuntu 18.04
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)]>
登录失败,类似遇到如下问题
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
(2 "No such file or directory")
查看服务运行状态 ,确保正常starting
● mariadb.service - MariaDB database server Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled) Active: failed (Result: timeout) since Sat 2018-08-04 19:21:07 CST; 24s ago Process: 17960 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=exited, status=0/SUCCESS) Process: 17873 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-environment _WSREP_START_POSITIO Process: 17871 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS) Process: 17869 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS) Main PID: 17960 (code=exited, status=0/SUCCESS) 8月 04 19:19:34 xxxxxxx systemd[1]: Starting MariaDB database server... 8月 04 19:19:35 xxxxxxx mysqld[17960]: 2018-08-04 19:19:35 140703912987776 [Note] /usr/sbin/mysqld (mysqld 10.1.29-MariaDB-6) starting as process 17960 ... 8月 04 19:21:05 xxxxxxx systemd[1]: mariadb.service: Start operation timed out. Terminating. 8月 04 19:21:07 xxxxxxx systemd[1]: mariadb.service: Failed with result 'timeout'. 8月 04 19:21:07 xxxxxxx systemd[1]: Failed to start MariaDB database server.
确保启动成功
sudo service mysql start
Job for mariadb.service failed because a timeout was exceeded. See "systemctl status mariadb.service" and "journalctl -xe" for details.
重装相关
#1,把原来的软件卸载掉
rpm -e mariadb-devel(后面自己一个一个卸载)
#2,删除之前卸载残留及配置文件
sudo find / -name "mariadb" -exec rm -rf {} \;
修改端口
# vi /etc/my.cnf.d/server.cnf [On CentOS/RHEL]
# vi /etc/mysql/mariadb.conf.d/50-server.cnf [On Debian/Ubuntu]
标签:MariaDB,service,数据库,sudo,server,mysql,mariadb,安装 From: https://www.cnblogs.com/kuozhen/p/18002316