How to use mysql?

本文详细介绍如何在Ubuntu系统上安装MySQL服务器,并提供解决安装失败的方法。此外,还介绍了如何启动、停止MySQL服务,如何连接MySQL数据库,以及如何设置远程访问权限。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值