0% found this document useful (0 votes)
4 views

10. MySQL Server

This document provides a comprehensive guide on setting up a MySQL server, including installation, configuration, and user management. It outlines the necessary requirements, step-by-step instructions for securing the server, creating users, and granting privileges. Additionally, it covers remote access setup and client installation for connecting to the MySQL server from another machine.

Uploaded by

aimanyusuf7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

10. MySQL Server

This document provides a comprehensive guide on setting up a MySQL server, including installation, configuration, and user management. It outlines the necessary requirements, step-by-step instructions for securing the server, creating users, and granting privileges. Additionally, it covers remote access setup and client installation for connecting to the MySQL server from another machine.

Uploaded by

aimanyusuf7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

SETUP MYSQL SERVER

By Ruzaini Roni © 2023. Politeknik Mukah

Introduction

MySQL is an Oracle-backed open source relational database management system (RDBMS)


based on Structured Query Language (SQL). MySQL runs on virtually all platforms, including
Linux, UNIX and Windows. Although it can be used in a wide range of applications, MySQL
is most often associated with web applications and online publishing. MySQL is an important
component of an open source enterprise stack called LAMP. The mysql-server package will
install the MySQL database server which you can interact with using a MySQL client.

Requirements
1. A machine as MySQL server
2. A client machine
3. DNS server is turned on
4. Privileged access to your Ubuntu system as root or via sudo command is required

Outcomes
You will provide a MySQL server to persist the data and provide a query interface for it (SQL).
You use the MySQL client to send commands to any MySQL server; on a dedicated remote
machine.

By Ruzaini Roni © 2023. Politeknik Mukah


Instructions

1. Back to the www machine and install the mysql-server package as following:

sudo apt install mysql-server

2. After the installation, run the security script: (Can skip this step, because there are update been doing
on mysql.

sudo mysql_secure_installation

Note: This changes some of the less secure default options for things like remote root logins
and sample users.

3. Press Enter and answer yes to set up the Validate Password Plugin, which can be
used to test the strength of your MySQL password.

4. Type 0 and press Enter for Low level of password validation policy (p/s: use for
learning purpose)

5. Enter and then confirm a secure password of your choice. (p/s: recommend
"abc@123" for learning purpose.

6. Type y and press Enter to remove anonymous users.

7. Type y and press Enter to Disallow root login remotely.

8. Type y and press Enter to remove test database and access to it.

Note: This will set a password for the MySQL root user, remove some anonymous users and
the test database, disable remote root logins, and load these new rules so that MySQL
immediately respects the changes you have made.

9. Type y and press Enter to reload privilege tables immediately

10. Execute the MySQL shell prompt from your terminal:

sudo mysql

11. Check which authentication method each of your MySQL user accounts use with the

following command:

By Ruzaini Roni © 2023. Politeknik Mukah


mysql> SELECT user,authentication_string,plugin,host FROM
mysql.user;

Note: You can see that the root user does in fact authenticate using the auth_socket plugin.

12. Configure the root account to authenticate with a password:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH


mysql_native_password BY 'password@123';

Note: password@123 is the password used for learning purpose

13. Reload the grant tables and put your new changes into effect:

mysql> FLUSH PRIVILEGES;

14. Check the authentication methods employed by each of your users again to confirm
that root no longer authenticates using the auth_socket plugin:

mysql> SELECT user,authentication_string,plugin,host FROM


mysql.user;

Note: You can see in this example output that the root MySQL user now authenticates using
a password.

15. Exit the MySQL shell:

mysql> exit

The following will run your MySQL client with regular user privileges.

16. Gain administrator privileges within the database:

By Ruzaini Roni © 2023. Politeknik Mukah


mysql –u root -p

17. Create a new user and give it a strong password:

mysql>CREATE USER 'admin'@'localhost' IDENTIFIED BY 'secure_password';

Note: Can replace 'secure_password' with strong password.

18. Then, grant your new user the privileges to all tables within the database, as well as
the power to add, change, and remove user privileges, with this command:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost';

mysql> GRANT GRANT OPTION ON *.* TO 'admin'@'localhost';


Note: at this point, you do not need to run the FLUSH PRIVILEGES command again. This
command is only needed when you modify the grant tables using statements like INSERT,
UPDATE, or DELETE. Because you created a new user, instead of modifying an existing one,
FLUSH PRIVILEGES is unnecessary here.
19. Exit the MySQL shell:

mysql> exit

20. Login to MySQL shell promt using admin account:

mysql -u admin -p

Note: put password that has been set before this.


21. If success, exit the MySQL shell:

mysql> exit

22. Login to MySQL shell promt using admin account:

The following will create the remote connection from a dedication address (or machine).

23. On the server, edit /etc/mysql/mysql.conf.d/mysqld.cnf file:

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

By Ruzaini Roni © 2023. Politeknik Mukah


24. Add the following entry to the mysqld.cnf file:

bind-address = 10.0.2.13

Note: This is IPv4 for MySQL server machine.

25. Login to MySQL shell promt using admin account:

mysql -u admin -p

26. Then, grant all tables within the database, as well as the power to add, change, and
remove user privileges, for user test1 from 10.0.2.11:

mysql> CREATE USER 'test1'@'10.0.2.11' IDENTIFIED BY 'test_123456';

27. Grant the user test1

mysql> GRANT ALL PRIVILEGES ON *.* TO 'test1'@'10.0.2.11';

28. Restart the service:

sudo systemctl restart mysql.service

29. Check the service status:

sudo systemctl status mysql.service

For an additional check, you can try connecting to the database using the
mysqladmin tool. For example, this command says to connect to MySQL as admin,
prompt for a password, and return the version:

sudo mysqladmin -p -u admin version

30. On the client machine (host 10.0.2.11, install mysql-client package.

sudo apt install mysql-client

31. After the installation, login to MySQL shell promt remotely using admin account:

mysql -u test1 –p –h 10.0.2.13

33. If success, then, exit the MySQL shell.

By Ruzaini Roni © 2023. Politeknik Mukah

You might also like