这里所说的基本配置主要用于建站等只需要连接数据库的方法。
首先更新软件源:
kate@kate:~$ sudo apt update
kate@kate:~$ sudo apt upgrade
首先安装MySQL:
kate@kate:~$ sudo apt install mysql
但是这里会报错:
kate@kate:~$ sudo apt install mysql
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package mysql
产生错误的原因是现在的Ubuntu软件源中已经不再预置MySQL,我们可以选择安装Mariadb,和MySQL是一样的功能:
注意这里是安装mariadb的服务端版本。
kate@kate:~$ sudo apt install mariadb-server
安装完毕之后,我们需要对数据库服务端进行配置:
首先进入数据库:
root@kate:/etc/apt# mysql -u root -p
输入密码直接回车,不用输入密码(因为没有设置),
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 49
Server version: 10.3.32-MariaDB-0ubuntu0.20.04.1 Ubuntu 20.04
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)]>
这样就进入了mariadb的命令行界面。首先要做的就是创建用户并赋权。在数据库的管理方面可以使用成熟的phpmyadmin进行的web管理,所以我们应当先为其创建一个用户来进行访问。
常用的命令有:
GRANT SELECT, INSERT ON test.user TO 'pig'@'%'; //为服务器%的用户pig赋权test数据库的user数据表
GRANT ALL ON *.* TO 'pig'@'%'; //为服务器%的用户pig赋权访问所有数据库
GRANT ALL ON maindataplus.* TO 'pig'@'%'; //为服务器%的用户pig赋权访问数据库maindataplus
在该页面下键入以下命令创建一个管理用户并为其赋权(请将password替换为自己的密码):
MariaDB [(none)]> grant all privileges on *.* to 'root'@'localhost' identified by 'password';
输入后显示:
Query OK, 0 rows affected (0.002 sec)
这时我们需要应用更改:
MariaDB [(none)]> flush privileges;
之后我们退出mariadb:
MariaDB [(none)]> exit;
接下来我们就可以通过phpmyadmin等进行web管理。