Installing MySql on Ubuntu

Software Developer. Interested in finding innovative solutions to problems.
for version 8.0.27
First install
my-sqldatabase:sudo apt install mysql-server # start the utility prompt to set the root user password sudo mysql_secure_installation utilityAllow remote access
sudo ufw enable sudo ufw allow mysqlStart the sql service
sudo systemctl start mysql # to allow the service to start at startup sudo systemctl enable mysqlStart mysql shell
/usr/bin/mysql -u root -pView users
SELECT User, Host, authentication_string FROM mysql.user;
Add a new user
gGive permission to the user to access some database
GRANT ALL ON database_name.* TO 'user_name'@'localhost';do
FLUSH PRIVILEGES;to reload the assigned permissions
Troubleshooting
If you face any permission issues while launching the
mysql- use
chown -R mysql:mysql filename
- use
Start
mysqlwithskip-grant-tablesmysqld --skip-grant-permissions --user=root
Resetting the root user password
If your data directory
/var/lib/mysqlcontains the old versionmysqlformat data, or something is wrong with it, regenerate it# Move or remove the original dir mv /var/lib/mysql /tmp/mysql # Create a new dir mkdir /var/lib/mysql # Change owner to mysql (user and group) chown -R mysql:mysql /var/lib/mysql # Create MySQL initial data mysqld --initializeNow start the
mysqldwithskip grant tables# starting the mysqld daemon sudo mysqld --skip-grant-tables --user=root # or if you can't open another terminal sudo mysqld --skip-grant-tables --user=root & # open mysql mysql -u rootFix the user permission table
UPDATE mysql.user SET authentication_string=null WHERE User='root'; FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd'; FLUSH PRIVILEGES; EXIT;Now you can login with the new password.



