Skip to content

Instantly share code, notes, and snippets.

@harireddy7
Created March 23, 2024 12:06
Show Gist options
  • Save harireddy7/42e924efad7a15799614bafbbd5faaaf to your computer and use it in GitHub Desktop.
Save harireddy7/42e924efad7a15799614bafbbd5faaaf to your computer and use it in GitHub Desktop.
Setup mysql on Ubuntu 22.04.4 LTS

Setup mysql on Ubuntu

  • Install mysql
  • Configure mysql server user
  • Install mysql-workbench

Install mysql

update the local packages

sudo apt-get update

install mysql-server with apt-get

sudo apt-get install mysql-server

verify installed version

mysql --version OR mysql -V 

# mysql  Ver 8.0.36-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu))

Check status of mysql-server

sudo systemctl status mysql

image

Configure mysql server user

Login with auth_socket plugin with sudo access

By default, auth_socket plugin enabled for root user, with this you can directly connect to mysql server using 👇

sudo mysql

# This will let you connect to mysql server

Check the user table to verify the authentication_string and plugin for root user -

SELECT user,authentication_string,plugin,host FROM mysql.user WHERE user="root";

image

Notice plugin is set to auth_socket, which enabes you to login to the MySQL server as root user with your sudo password.

Create user and password to connect to mysql db server

In order to login using password, you need to update the plugin column value for root user.

You can change it to caching_sha2_password to login with password

Login with sudo mysql and update the plugin column

sudo mysql

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'PROVIDE_YOUR_PASSWORD_HERE';

# once updated, clear the privileges to reload user 
mysql> FLUSH PRIVILEGES;

image

Now you can connect to mysql db with user and password 👇

mysql -u root -p
Enter password: xxxxxxxx

# This will now let you login to sql server

Install mysql workbench

This is a graphical user interface used to connect to mysql server.

Download mysql-workbench from 👉 https://dev.mysql.com/downloads/workbench/.

Say you download mysql-workbench-community_8.0.36-1ubuntu22.04_amd64.deb

#Install it using dpkg

sudo dpkg -i mysql-workbench-community_8.0.36-1ubuntu22.04_amd64.deb

In case if you get any dependency errors, run these commands to fix the installation

sudo apt-get install gnome-menus

# choose Yes when asked for confirmation

sudo apt --fix-broken install

Verify mysql-workbench version

mysql-workbench --version

# Found /lib/x86_64-linux-gnu/libproj.so.22
# MySQL Workbench CE (GPL) 8.0.36 CE build 3737333

Launch the workbench with 👇

mysql-workbench

# This should open the mysql workbench graphical user interface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment