Ubuntu安装Mysql数据库

1、首先查看Ubuntu中是否安装过mysql,使用如下命令。

dpkg -l | grep mysql

若没有安装则不会出现任何提示,如下图是安装过的。

2、安装mysql-server

sudo apt install mysql-server

Ubuntu安装Mysql数据库_第1张图片

3、 再次验证是否安装mysql,上面有截图

dpkg -l | grep mysql

root@Eth002:/home/caojun/FISCO/WeBASE-Node-Manager# dpkg -l | grep mysql
ii  mysql-client-5.7                       5.7.40-0ubuntu0.18.04.1                   amd64        MySQL database client binaries
ii  mysql-client-core-5.7                  5.7.40-0ubuntu0.18.04.1                   amd64        MySQL database core client binaries
ii  mysql-common                           5.8+1.0.4                                 all          MySQL database common files, e.g. /etc/mysql/my.cnf
ii  mysql-server                           5.7.40-0ubuntu0.18.04.1                   all          MySQL database server (metapackage depending on the latest version)
ii  mysql-server-5.7                       5.7.40-0ubuntu0.18.04.1                   amd64        MySQL database server binaries and system database setup
ii  mysql-server-core-5.7                  5.7.40-0ubuntu0.18.04.1                   amd64        MySQL database server binaries

 该命令也可以进行验证

netstat -tap | grep mysql

 在控制台输入下面的命令进行登录

mysql -u root -p

Ubuntu安装Mysql数据库_第2张图片

 查看数据库

show databases;

Ubuntu安装Mysql数据库_第3张图片

创建数据库,直接复制即可,创建一个node的数据库。

CREATE DATABASE IF NOT EXISTS node DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

 Ubuntu安装Mysql数据库_第4张图片

 exit退出控制台

 初始化mysql数据库,退出mysql控制台后使用如下命令

mysql_secure_installation

Ubuntu安装Mysql数据库_第5张图片

 下面会出现一些选项配置,可以按照自己需要进行配置

1、首先是安装验证插件,选择N

Ubuntu安装Mysql数据库_第6张图片

 2、设置root的密码,重复输入两次

Ubuntu安装Mysql数据库_第7张图片

 3、删除匿名账户

4、删除默认的测试数据库

Ubuntu安装Mysql数据库_第8张图片

5、刷新授权的

Ubuntu安装Mysql数据库_第9张图片

 6、查看mysql运行状态

systemctl status mysq

 7、配置mysql远程访问机制,注销这一行(43行),保存退出

vim /etc/mysql/mysql.conf.d/mysqld.cnf

Ubuntu安装Mysql数据库_第10张图片

 在[mysqld]里面添加 skip-grant-tables

Ubuntu安装Mysql数据库_第11张图片

 8、进行mysql控制台进行刷新权限,如下命令按照顺序执行即可

mysql -u root -p
grant all on *.* to root@'%' identified by '123456' with grant option;
flush privileges;
exit
systemctl restart mysql
systemctl status mysql

 9、远程连接,在另外一台电脑上面进行远程连接测试,输入mysql数据库电脑的ip及数据库3306端口、用户名、密码

Ubuntu安装Mysql数据库_第12张图片

 这里就是新建的数据库

Ubuntu安装Mysql数据库_第13张图片

附上:

root@Eth002:/home/caojun/FISCO/WeBASE-Node-Manager/dist/script# mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: N
Please set the password for root here.

New password: 

Re-enter new password: 
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 

你可能感兴趣的:(Linux操作系统,mysql,数据库,ubuntu)