search
HomeDatabaseMysql TutorialStep-by-step guide for how to install an SQL server on Ubuntu 04

Step-by-step guide for how to install an SQL server on Ubuntu 22.04

Step-by-step guide for how to install an SQL server on Ubuntu 04

Installing the SQL server

Firstly update your desktop and install the SQL server

sudo apt-get update

sudo apt-get install mysql-server

Verify that the server is running with the following command

sudo systemctl start mysql.service

sudo systemctl status mysql.service

The result should look like this:

live MySQL server

Configure MySQL

You will need to set the password for the root account if you are running the installation on an Ubuntu machine because authentication is deactivated on Ubuntu by default. So as to avoid an error, you’ll need to configure the root account authentication method

sudo mysql

Change the password for root using ALTER USER:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Exit after making this change

mysql> exit

Secure your MySQL root user account

In securing your server, you will need to execute the following command to setup your password policy

sudo mysql_secure_installation

The password policy given will apply to subsequent users accounts created.

The next is to authenticate using the root user’s password:

mysql -u root -p

This command gives the root user access to the MySQL cli, and also to interact directly with the MySQL server.

Then go back to using the default authentication method using this command:

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

This will allow you connect using the sudo mysql command again.

Creating default/new MySQL user and its privileges

It is bad OpSec to use the root account to perform regular day-to-day action on the database. The best option is to create a user account with limited privileges.

This is first done by logging in as root with the following command:

sudo mysql

Alternatively, if you have previously set a password for the root account use this instead:

mysql -u root -p

Next create a new user:

mysql> CREATE USER 'username'@'host' IDENTIFIED WITH authentication_plugin BY 'password';

After entering the command, follow the prompt and fill in your username, hostname (localhost if you’re using Ubuntu).

For authentication, you have the options of using auth_socket plugin which provides string security without requiring a password but has a shortcoming of preventing remote connections,authentication_plugin plugin, caching_sha2_password which is the default MySQL plugin, but its shortfall is that some versions of PHP are not compatible with it or mysql_native_password plugin.

mysql> CREATE USER 'jack'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

You can also alter an existing user using:

mysql> ALTER 'jack'@'hostname' IDENTIFIED WITH mysql_native_password BY 'password';

Assigning privileges

After creating the user, you can assign it with privileges with the following syntax.

mysql> GRANT PRIVILEGE ON database.table TO 'username'@'host';

Using GRANT ALL PRIVILEGES instead will give the user superuser privileges similar to that of root. Such flag will otherwise defeat the purpose of creating a separate user account from root.

The PRIVILEGE variable represents what action a user is allowed to perform. Global privileges can also be granted by replacing database.table with *.

Below we will be granting user permissions to create, modify, delete, insert, select, update and delete data from a table by using CREATE, ALTER, DROP, INSERT, SELECT, UPDATE and DELETE respectively.

mysql> GRANT CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT on *.* TO 'jack'@'hostname' WITH GRANT OPTION;

The WITH GRANT OPTION flag allows the user to grant privileges it has to other users.

Next we will use the FLUSH PRIVILEGES command to empty the cache and free up memory:

mysql> FLUSH PRIVILEGES;

After you can exit the MySQL cli

mysql> exit

You can now log in back using your credentials

mysql -u jack -p

Testing the MySQL server

You can now verify that the MySQL server is running with the following command:

systemctl status mysql.service

Alternatively, you can connect to the MySQL database using the administrative command tool mysqladmin.

sudo mysqladmin -p -u jack version

The above is the detailed content of Step-by-step guide for how to install an SQL server on Ubuntu 04. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How do you alter a table in MySQL using the ALTER TABLE statement?How do you alter a table in MySQL using the ALTER TABLE statement?Mar 19, 2025 pm 03:51 PM

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

How do I configure SSL/TLS encryption for MySQL connections?How do I configure SSL/TLS encryption for MySQL connections?Mar 18, 2025 pm 12:01 PM

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

How do you handle large datasets in MySQL?How do you handle large datasets in MySQL?Mar 21, 2025 pm 12:15 PM

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

How do you drop a table in MySQL using the DROP TABLE statement?How do you drop a table in MySQL using the DROP TABLE statement?Mar 19, 2025 pm 03:52 PM

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

How do you represent relationships using foreign keys?How do you represent relationships using foreign keys?Mar 19, 2025 pm 03:48 PM

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

How do you create indexes on JSON columns?How do you create indexes on JSON columns?Mar 21, 2025 pm 12:13 PM

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)?How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)?Mar 18, 2025 pm 12:00 PM

Article discusses securing MySQL against SQL injection and brute-force attacks using prepared statements, input validation, and strong password policies.(159 characters)

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor