Location>code7788 >text

Installing MySQL in ubuntu

Popularity:411 ℃/2024-10-08 14:36:51

Installation Steps:

  1. sudo apt-get update
  2. sudo apt-install mysql-server
  3. sudo apt-get install libmysqlclient-dev
    If you want to install the specified version you can refer to this /weixin_45562068/article/details/131805863

Check if the service is running

systemctl status mysql
image

Change user name and password

sudo vim /etc/mysql/
image

Connecting to the database
utilizationmysql -u [user] -p[password]
image

Next change the username and password:
Changing a username directly is not a recommended operation in MySQL because it can lead to permissions and ownership issues. Instead, it is common practice to create a new user, grant it the necessary permissions, and then delete the old user.

Create a new user:

Use the CREATE USER statement to create a new user.

CREATE USER 'new_username'@'localhost' IDENTIFIED BY 'new_password';

image

Replace new_username with your new username, localhost with the hostname, and new_password with your new password.

Granting Permissions:

Use the GRANT statement to grant the old user's privileges to the new user.

GRANT ALL PRIVILEGES ON *.* TO 'new_username'@'localhost';

image

Adjust permissions and database objects as needed.

Update permissions:

If there are any stored programs or views that use the old username, you will need to update them to use the new username.

Delete the old user:

Use the DROP USER statement to delete the old user.

DROP USER 'old_username'@'localhost';

Replace old_username with the old username.
image

Refresh permissions:

Execute the following command to make the permission changes take effect.

FLUSH PRIVILEGES;

image

Test Login

Connect using the username and password you just set up. After successful configuration as shown below.
image

At this point the use of Ubuntu configuration mysql has all finished, you can happily use the database ah.