Install MySQL under Ubuntu

You need to build a website, except for the web, which is the database, and the LAMP suite is "Linux+Apache+Mysql+PHP. These four software forms a package tool software that can run the website.

1、 MySQL installation

sudo apt-get install mysql-server mysql-client

Enter the password of the root user: 123456, press Enter

enter:

sudo apt install libmysqlclient-dev 

Completed the MySQL installation!

2、 Test whether the installation is successful

sudo netstat -tap | grep mysql 

enter:

mysql -uroot -p

View the database:

show databases;

Select the mysql database:

use mysql;

Check the "user" table of the database "mysql" to see if the host corresponding to root is set correctly:

select user, host from user;

If host is localhost, remote access is not allowed; it needs to be changed to% to indicate remote access.

The% means to allow all ip remote access, if you need to specify a specific ip, just write the specific ip

Update the user table:

update user set host ='%' where user ='root' limit 1;

Force refresh permissions

flush privileges;

3、 Connect to MySQL

We use Navicat under Windows7 to connect to MySQL under Ubuntu

Use # sudo ifconfig to get the ip address of Ubuntu (make sure that Ubuntu and Windows are on the same network segment!)

Ubuntu's ip is 192.168.1.127, remember!

Open Navicat under Windows, connect, MySQL,

Enter the password of ip and root, click test connection

It prompts that you cannot connect to Ubuntu's MySQL. Generally, you can connect to the remote server's MySQL. If there is a problem, the big problem will be the server port and authorization problem.

Solution:

First we pass

①:

netstat -an|grep 3306

To check whether the default port 3306 of mysql is open, which ip is allowed to use, if you find that there is 127.0.0.1 in front, it means that port 3306 can only be used by the local ip

So we need

②: Open the mysql configuration file

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

If MariaDB is installed, the mysql configuration file is in:

vim /etc/mysql/mariadb.conf.d/50-server.cnf

Comment out bind-address = 127.0.0.1

③: Enter mysql, authorize remote users,

grant all privileges on *.* to 'root'@'%' identified by 'xxxxxx';

Here root is the user you log in remotely, xxxxxx is the password you use to log in, and then you can see in the mysql data table that your user has been added to the user table

Then restart mysql:

service mysql restart

or:

/etc/init.d/mysql stop

/etc/init.d/mysql start

Then enter Navicat to reconnect to test, this time Ok!

Click OK to confirm.

4、 MySQL operation

**Log in to the database: **

mysql -u root -p

**User authorization: **

grant all privileges on *.* to root@"%" identified by "root"with grant option;

The first command is explained as follows, .: The first * represents the database name; the second * represents the table name. This means that all tables in all databases are authorized to users. root: Grant the root account.

"%": Indicates that the authorized user IP can be specified, which means that any IP address can access the MySQL database. "Password": Assign the password corresponding to the account, where the password is replaced with your mysql root account password.

**Refresh permission information: **

flush privileges;

**Start the MySQL service: **

 sudo start mysql

**Stop MySQL service: **

sudo stop mysql

**Modify the MySQL administrator password: **

sudo mysqladmin -u root password newpassword

Set up remote access (under normal circumstances, port 3306 occupied by mysql is only monitored on IP 127.0.0.1, and access to other IPs is denied (you can view it through netstat). Cancel local monitoring

Listen to need to modify the my.cnf file:):

sudo vim /etc/mysql/my.cnf

bind-address = 127.0.0.1 //Find this content and comment

Analysis of the directory structure after MySQL installation (this structure is only for online installation using apt-get install):

Database storage directory: /var/lib/mysql/

Related configuration file storage directory: /usr/share/mysql

The relevant command storage directory: /usr/bin (mysqladmin mysqldump and other commands)

Startup script storage directory: /etc/rc.d/init.d/

Recommended Posts

Install mysql under Ubuntu 16.04
Install MySQL under Ubuntu
Install MySQL under Ubuntu 18.04 (graphic tutorial)
Install apache+PHP under Ubuntu
Install python3.6 under Ubuntu 16.04
Install mysql5.7 under CentOS7
Install Thrift under ubuntu 14.10
Install OpenJDK10 under Ubuntu
Install Caffe under Ubuntu 14.04
Install mysql on Ubuntu 14.04
2018-09-11 Install arduino under Ubuntu
Ubuntu19 install MySQL pit
Install mysql under Centos 7
Install ROS under ROS Ubuntu 18.04[2]
Install mysql5.1 under CentOS6.5
Install Yarm-PM2 under Ubuntu
Install MySQL under Linux (CentOS 7)
Install Mysql offline on Ubuntu
Install server-side Shadowsocks under Ubuntu 16.04
Install rgl package under Ubuntu
How to install MySQL on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
Install and configure MySQL on Ubuntu
Install 3 single-cell R packages under Ubuntu
How to install mysql in Ubuntu 14.04
Install and deploy Gerrit under Ubuntu
Install JDK1.8 original under Ubuntu Kylin
Small tool: install screenshot tool under ubuntu
Install nodejs and npm under Ubuntu 16.04
Ubuntu install MySQL password initialization problem
How to install mysql in Ubuntu 14.04
How to install MySQL on Ubuntu 14.04
How to install Audacious under Ubuntu
How to install Tensorflow under ubuntu 16.04
Compile and install QEMU under Ubuntu
CentOS7.2 install Mysql5.7.13
CentOS7 install MySQL
ubuntu18.04 install python2
ubuntu18.04 install docker
ubuntu12.04 install python3
Ubuntu install guide
ubuntu 16 install asp.net
ubuntu install leanote
CentOS install mysql
ubuntu install Jenkins
CentOS7 install mysql
CentOS 7 install MySQL 5.6
docker install ubuntu
ubuntu install elasticsearch
CentOS8 install MySQL8.0
CentOS7 install mysql8
Ubuntu14 upgrade MySQL
CentOS7 install MySQL8
ubuntu16.0.1 install pagoda
ubuntu18.04 install python
centos 7.5 install mysql5.7.17
ubuntu 18.04 install teamviewer
ubuntu install sendmail
Install linux (ubuntu) dual system under windows system
How to install MySQL on Ubuntu 18.04 (linux)
Install YouCompleteMe plugin for vim under Ubuntu