How to use mysql?
How to install mysql?
My computer is in ubuntu :linux deepin 3.2.0-26-generic.
In any dictionary,type:sudo apt-get install mysql-server
it will run automantically.usually ,it will pop a window to ask you to input a password for root
user.
if you failure in install because last install failure,it will print a message like this:
Unable to set password for the Mysql "root" user
An error occurred while setting password for the mysql
This may have happened because the account already has a password,
or because of a communication problem with the Mysql server.
You should check the account's password after the package installation.
Please read the /usr/share/doc/mysql-server-5.5/README.Debian file for more information.
So you should remove last falure install like these:
sudo dpkg --purge mysql-client-core-5.5 # or alternative version
sudo dpkg --purge mysql-client
sudo dpkg --purge mysql-server-core-5.5 # or alternative version
sudo dpkg --purge mysql-common
Basically I just type
sudo dpkg --purge mysql # followed by two tabs
Then –purge any packages the terminal auto-completes. Purge mysql-common at last because of some dependency problems.
Use above dpkg commands in addition to
sudo apt-get --purge remove mysql-server
sudo apt-get --purge remove mysql-client
sudo apt-get --purge remove mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
Also I tried Greq’s method
sudo rm -rf /etc/mysql
Remove the mysql folder from /var/lib
sudo rm -rf /var/lib/mysql/
At this point, to make sure mysql is fully removed, check with
which mysql
mysql --version
the last two commond is check if mysql is deleted clean.
and then,you can reinstall mysql by first commond .
How to stop ,start mysql?
sudo /etc/init.d/mysql start(or stop,restart)
How to connect to mysql ?
mysql -u username -p
How to use mysql from other computer?
By default mysql is only can be used in localhost,you can visit it from other computer by do like these:
logging in mysql by :
mysql -u root -p
grant all privileges on 你想让这个用户访问的数据库 to username@'ip地址'或者'%'(就不限制ip地址了)
identified by 'password'
例子:
mysql> grant all privileges on . to han@’%’ identified by “123456”
mysql>use mysql
mysql> select host ,user,password from user;
+———–+——————+——————————————-+
| host | user | password |
+———–+——————+——————————————-+
| localhost | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| deepin | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| 127.0.0.1 | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| ::1 | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| localhost | debian-sys-maint | *4E922998EE5880CD4BDB02EB240F661626F61752 |
| % | han | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+———–+——————+——————————————-+
6 rows in set (0.00 sec)
mysql>
Now you can visit mysql from other computer:
mysql -h mysql所在的机器 -u username -p password