How to install MySQL on Ubuntu
Step by Step Guide on How to Install MySQL Server on Ubuntu VM
Update Package List:
Start by updating the package list on your Ubuntu server to ensure you have the latest information about available packages:
sudo apt update
Install MySQL Server:
Use the following command to Install MySQL Server
sudo apt install mysql-server
Secure MySQL Installation:
After MySQL server is Installed, you should run a security script that comes with MySQL to improve its security. Run the following command and follow the on-screen prompts:
sudo mysql_secure_installation
This script will help you set a root password, remove anonymous users, disallow remote root login, and remove the test database.
Start and Enable MySQL:
Start the MySQL service and enable it to start automatically on boot:
sudo systemctl start mysql sudo systemctl enable mysql
Check MySQL Service Status:
Verify that MySQL is running without any issues by using the following command:
sudo systemctl status mysql
You should see “active (running)” in the output if MySQL is running correctly.
Access MySQL:
You can access the MySQL server with the following command. Replace your_password
with the root password you set during the installation process:
sudo mysql -u root -p
This will prompt you for the root password. Once you enter it, you will be in the MySQL shell like below.
Create Databases, Use or Drop Database :
If you need to create the databases or drop the databases use the following commands
CREATE DATABASE mydb;
USE mydb;
DROP DATABSE mydb;
Create User and Grant Permissions :
CREATE USER 'user'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON your_database.* TO 'your_user'@'localhost'; FLUSH PRIVILEGES;
How to Create a Table in MySQL :
CREATE TABLE mytable ( ID int, FirstName varchar(255), lastName varchar(255), Address varchar(255), Age int );
How to Insert Records in a Table in MySQL :
INSERT INTO mytable (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
Exit MySQL Shell:
To exit from MySQL shell just enter like below
exit
By using the above steps now we are able to how to install MySQL server on Ubuntu VM
it’s a good idea to refer to the latest documentation for the most accurate instructions. the official MySQL Documentation for more advanced features and setup options.