How to install and use mysql
windows
installation
Install mysql on windows, click to learn how to download
problem
After installing mysql, open mysql shell
, input mysql -u root -p
can, then enter the password you set. If you encounter the following interface
solution:
Mysql JS> \sql
Mysql SQL> \connect root@localhost
linux
installation
Take ubuntu
an example
sudo apt-get update
sudo apt-get install python3-setuptools
sudo apt-get install python3-dev
sudo python3 setup.py install
sudo apt-get install mysql-server mysql-client
If you are asked to enter a password during the installation process, this password must be remembered!
Then enter the command
mysql -u root -p
Enter the password you set to enter the database.
problem
You were not asked to set a password during the installation process.
fatpuffer@ubuntu:~/Downloads$ mysql -uroot -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
- Enter sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf on the terminal of ubuntu, enter the configuration file, and then add skip- to the [mysqld] section of the configuration file The sentence grant-tables.
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
character-set-server=utf8
collation-server=utf8_general_ci
skip-grant-tables
- The effect is that you can log in to mysql without a password.
- Save: wq, exit. Input: service mysql restart, restart mysql.
- Enter mysql -u root -p on the terminal, and press Enter when you are prompted to enter the password. After entering mysql, execute the following three sentences:
use mysql; 然后敲回车
update user set authentication_string=password("你的密码") where user="root"; 然后敲回车
flush privileges; 然后敲回车
- Then enter quit to exit mysql.
- Re-enter the mysqld.cnf file to comment out the skip-grant-tables statement added at the beginning.
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
character-set-server=utf8
collation-server=utf8_general_ci
# skip-grant-tables
-
Return to the terminal and enter mysql -uroot -p, and you should be able to enter the database.
-
If an error is still reported at this time, then you need to return to step 3, re-validate the commented statement (that is, delete the # symbol), re-enter mysql, first select a database (use mysql), and then enter
select user,plugin from user
-
It can be seen that after executing select user and plugin from user, the cause of the error is because the field of plugin root is auth_socket, then we can change it to the following mysql_native_password. enter:
update user set authentication_string=password("ln122920"),plugin='mysql_native_password' where user='root'
- Then press Enter to execute the following, and then enter
select user,plugin from user;
- Exit mysql
\quit
- Restart mysql
service mysql restart
Then this problem is completely solved.