记MySQL在Ubuntu(18.04.1 LTS)的安装

本文记录一次在Ubuntu(18.04.1 LTS)上安装MySql过程,安装后的mySQL版本为5.7.24。

安装环境
[email protected]~virtual-machine:/etc# cat /etc/issue
Ubuntu 18.04.1 LTS
安装mySql

以下为按照命令,在提示需要输入 [Y/n] 时,输入Y.

[email protected]~virtual-machine:~# sudo apt-get install mysql-server
[email protected]~virtual-machine:~# sudo apt-get install mysql-client
[email protected]~virtual-machine:~# sudo apt-get install libmysqlclient-dev
[email protected]~virtual-machine:~#

安装完成后,进入mySql

[email protected]~virtual-machine:~# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql>

建立一个用户并授权。

mysql> GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.03 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

修改mysqld.cnf配置并重启MySQL服务

在安装好后,需要修改MySQL配置,否则其他的数据电脑或虚拟机不能连接该MySQL服务。在/etc/mysql/mysql.conf.d/mysqld.cnf里面,注掉或者删掉bind-address = 127.0.0.1”,或者将bind-address = 127.0.0.1修改为“bind-address = 0.0.0.0”。

[email protected]~virtual-machine:~# vi /etc/mysql/mysql.conf.d/mysqld.cnf
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address           = 127.0.0.1

bind-address修改后,需要重启mySQL服务。

[email protected]~virtual-machine:~# service mysql restart

通过Navicat 或者SQL Developer工具连接

在以上步骤完成后,可以通过Navicat或SQL Developer工具连接到已安装的MySQL。此处使用SQL Developer连接到安装的MySQL。

连接名(M):自己定义
用户名(U):该值为前面创建的用户user
口令(P):该值为前面创建的密码password
主机名(A):主机名为MySQL安装的地址
端口(R):端口为MySQL服务监听端口
记MySQL在Ubuntu(18.04.1 LTS)的安装