How to use mysql?

来源:互联网 发布:什么是观测数据 编辑:程序博客网 时间:2024/05/22 00:51

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" userAn error occurred while setting password for the mysqlThis 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 versionsudo dpkg --purge mysql-clientsudo dpkg --purge mysql-server-core-5.5 # or alternative versionsudo 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-serversudo apt-get --purge remove mysql-clientsudo apt-get --purge remove mysql-commonsudo apt-get autoremovesudo apt-get autoclean

Also I tried Greq’s method

sudo rm -rf /etc/mysqlRemove the mysql folder from /var/libsudo rm -rf /var/lib/mysql/At this point, to make sure mysql is fully removed, check withwhich mysqlmysql --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 -pgrant 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
0 0