- Linux:Powerful Server Administration
- Uday R. Sawant Oliver Pelz Jonathan Hobson William Leemans
- 569字
- 2021-07-09 18:16:54
Installing relational databases with MySQL
In this recipe, we will learn how to install and configure the MySQL database on an Ubuntu server.
Getting ready
You will need access to a root account or an account with sudo
privileges.
Make sure that the MySQL default port 3306
is available and not blocked by any firewall.
How to do it…
Follow these steps to install the relational database MySQL:
- To install the MySQL server, use the following command:
$ sudo apt-get update $ sudo apt-get install mysql-server-5.7
The installation process will download the necessary packages and then prompt you to enter a password for the MySQL root account. Choose a strong password:
- Once the installation process is complete, you can check the server status with the following command. It should return an output similar to the following:
$ sudo service mysql status mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service Active: active (running) since Tue 2016-05-10 05:
- Next, create a copy of the original configuration file:
$ cd /etc/mysql/mysql.conf.d $ sudo cp mysqld.cnf mysqld.cnf.bkp
- Set MySQL to listen for a connection from network hosts. Open the configuration file
/etc/mysql/mysql.conf.d/mysqld.cnf
and changebind-address
under the[mysqld]
section to your server’s IP address:$ sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf bind-address = 10.0.2.6
Note
For MySQL 5.5 and 5.6, the configuration file can be found at
/etc/mysql/my.cnf
- Optionally, you can change the default port used by the MySQL server. Find the
[mysqld]
section in the configuration file and change the value of theport
variable as follows:port = 30356
Make sure that the selected port is available and open under firewall.
- Save the changes to the configuration file and restart the MySQL server:
$ sudo service mysql restart
- Now open a connection to the server using the MySQL client. Enter the password when prompted:
$ mysql -u root -p
- To get a list of available commands, type
\h
:mysql> \h
How it works…
MySQL is a default database server available in Ubuntu. If you are installing the Ubuntu server, you can choose MySQL to be installed by default as part of the LAMP stack. In this recipe, we have installed the latest production release of MySQL (5.7) from the Ubuntu package repository. Ubuntu 16.04 contains MySQL 5.7, whereas Ubuntu 14.04 defaults to MySQL version 5.5.
If you prefer to use an older version on Ubuntu 16, then use following command:
$ sudo add-apt-repository ‘deb http://archive.ubuntu.com/ubuntu trusty universe’ $ sudo apt-get update $ sudo apt-get install mysql-server-5.6
After installation, configure the MySQL server to listen for connections from external hosts. Make sure that you open your database installation to trusted networks such as your private network. Making it available on the Internet will open your database to attackers.
There’s more…
Securing MySQL installation
MySQL provides a simple script to configure basic settings related to security. Execute this script before using your server in production:
$ mysql_secure_installation
This command will start a basic security check, starting with changing the root
password. If you have not set a strong password for the root account, you can do it now. Other settings include disabling remote access to the root account and removing anonymous users and unused databases.
MySQL is popularly used with PHP. You can easily install PHP drivers for MySQL with the following command:
$ sudo apt-get install php7.0-mysql
See also
- The Ubuntu server guide mysql page at https://help.ubuntu.com/14.04/serverguide/mysql.html
- 大數(shù)據(jù)項(xiàng)目管理:從規(guī)劃到實(shí)現(xiàn)
- 數(shù)控銑削(加工中心)編程與加工
- 大數(shù)據(jù)平臺(tái)異常檢測分析系統(tǒng)的若干關(guān)鍵技術(shù)研究
- Maya極速引擎:材質(zhì)篇
- Windows 7寶典
- 計(jì)算機(jī)網(wǎng)絡(luò)原理與技術(shù)
- 自動(dòng)化生產(chǎn)線安裝與調(diào)試(三菱FX系列)(第二版)
- Apache源代碼全景分析(第1卷):體系結(jié)構(gòu)與核心模塊
- 空間機(jī)器人
- INSTANT Adobe Story Starter
- Building Google Cloud Platform Solutions
- MPC5554/5553微處理器揭秘
- 人工智能:智能人機(jī)交互
- 計(jì)算智能算法及其生產(chǎn)調(diào)度應(yīng)用
- Hands-On Deep Learning with Go