Install and completely delete mysql5.7 under ubuntu16.04

created at 07-27-2021 views: 2

Delete mysql5.7 completely

#The following commands are executed in sequence

sudo rm /var/lib/mysql/ -R # delete database directory
sudo rm /etc/mysql/ -R # Delete startup scripts, configuration files, etc.
sudo apt-get autoremove mysql* --purge # uninstall all mysql files
sudo apt-get remove apparmor # This apparmor is installed in the mysql-server fashion, and is related to security

dpkg -l |grep ^rc|awk'{print $2}' |sudo xargs dpkg -P # Clean up residual mysql files

Installation of mysql5.7

sudo apt-get install mysql-server

The above command will install the following packages:

apparmor 
mysql-client-5.7 
mysql-common 
mysql-server 
mysql-server-5.7 
mysql-server-core-5.7

Therefore, there is no need to install mysql-client and so on. The installation process will prompt to set the password of the mysql root user. After the setting is completed, wait for the automatic installation. The default installation is complete and mysql is started

Tips: The installation process will prompt to enter the root password, please remember the password yourself, otherwise it will be very troublesome.

After installation, check whether the installation is successful:

sudo netstat -tap | grep mysql

If you see that the mysql socket is in the listen state, it means the installation is successful.

Next use the command to log in to mysql

mysql -u root -p

Common naming:

ubuntu mysql start/stop/restart commands

Several important directories of MySQL

After MySQL is installed, unlike SQL Server, it is installed in a directory by default. Its database files, configuration files, and command files are in different directories. It is very important to understand these directories, especially for beginners of Linux, because the directory structure of Linux itself It's more complicated. If you don't know the MySQL installation directory, then you can't talk about in-depth study.

Here are some of these directories.

  1. Database directory    /var/lib/mysql/
  2. Configuration file    /usr/share/mysql (mysql.server command and configuration file)
  3. Related commands    /usr/bin (commands such as mysqladmin mysqldump)
  4. Start the script    /etc/rc.d/init.d/ (start script file mysql

Set mysql to allow remote access

First edit the file /etc/mysql/mysql.conf.d/mysqld.cnf:

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

# If you are prompted that vim does not have this command, please install vim
# sudo apt-get install vim

Comment out bind-address = 127.0.0.1:
created at:07-27-2021
edited at: 07-27-2021: