mysql安装

一、ubtunu14(安装)

1.查看是否安装过mysql

sudo  netstat -tap | grep mysql

若出现表示已经存在mysql数据库

haodai@haodai-virtual-machine:~$ sudo netstat -tap | grep mysql
[sudo] password for haodai:
tcp        0      0 *:mysql                 *:*                     LISTEN      1296/mysqld     
tcp        0      0 192.168.5.102:mysql     192.168.5.113:51184     ESTABLISHED 1296/mysqld     
tcp        0      0 192.168.5.102:mysql     192.168.5.113:51183     ESTABLISHED 1296/mysqld     
haodai@haodai-virtual-machine:~$

2卸载mysql

2.1.删除mysql的数据文件

sudo rm /var/lib/mysql/ -R

2.2.删除mysql的配置文件

sudo rm /etc/mysql/ -R

2.3.自动卸载mysql

sudo apt-get autoremove mysql* --purge
sudo apt-get remove apparmor

3使用 sudo apt-get install mysql-server mysql-client安装数据库

如果在其中出现依赖错误可以使用sudo apt-get -f install修复依赖

haodai@sh-135-haodai:~$ sudo apt-get install mysql-server mysql-client
sudo: unable to resolve host sh-135-haodai
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gir1.2-json-1.0 gir1.2-timezonemap-1.0 gir1.2-xkl-1.0
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  libdbd-mysql-perl libdbi-perl libhtml-template-perl libterm-readkey-perl
  mysql-client-5.5 mysql-client-core-5.5 mysql-common mysql-server-5.5
  mysql-server-core-5.5
Suggested packages:
  libmldbm-perl libnet-daemon-perl libplrpc-perl libsql-statement-perl
  libipc-sharedcache-perl tinyca mailx
The following NEW packages will be installed:
  libdbd-mysql-perl libdbi-perl libhtml-template-perl libterm-readkey-perl
  mysql-client mysql-client-5.5 mysql-client-core-5.5 mysql-server
  mysql-server-5.5 mysql-server-core-5.5
The following packages will be upgraded:
  mysql-common
1 upgraded, 10 newly installed, 0 to remove and 480 not upgraded.
Need to get 8,892 kB of archives.
After this operation, 93.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

出现该界面填写root初始密码

 安装完成出现

haodai@sh-135-haodai:~$ sudo netstat -tap  | grep mysql
sudo: unable to resolve host sh-135-haodai
tcp        0      0 localhost:mysql         *:*                     LISTEN      8841/mysqld     

4.进入mysql客户端

haodai@sh-135-haodai:~$ mysql -uroot -proot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 42
Server version: 5.5.61-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

5.设置mysql远程访问权限

5.1授权法 with grant option(该句表示该用户可以授权给其他用户)

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> grant all privileges on *.* to root@'%'identified by "password" with grant option;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> seletc host,user,password from user;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'seletc host,user,password from user' at line 1
mysql> select host,user,password from user;
+---------------+------------------+-------------------------------------------+
| host          | user             | password                                  |
+---------------+------------------+-------------------------------------------+
| localhost     | root             | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| sh-135-haodai | root             | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| 127.0.0.1     | root             | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| ::1           | root             | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| localhost     | debian-sys-maint | *8877366A4AE1E2937A4FB50E149A499FA0FF53FF |
| %             | root             | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
+---------------+------------------+-------------------------------------------+
6 rows in set (0.00 sec)

mysql>

5.1.1使用sudo net -anpt | grep mysql如果出现以下表示只监听了本地IP仍然不能远程访问

haodai@sh-135-haodai:~$ sudo netstat -anpt | grep mysql
sudo: unable to resolve host sh-135-haodai
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      8841/mysqld     
haodai@sh-135-haodai:~$

5.1.2解决办法:(修改mysql配置文件中的bind-address=0.0.0.0)

haodai@sh-135-haodai:/etc/mysql$ sudo vim /etc/mysql/my.cnf

skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 0.0.0.0
#
# * Fine Tuning

5.1.3重启mysql

haodai@sh-135-haodai:/etc/mysql$ sudo service mysql stop
sudo: unable to resolve host sh-135-haodai
mysql stop/waiting
haodai@sh-135-haodai:/etc/mysql$ sudo netstat -anpt | grep mysql
sudo: unable to resolve host sh-135-haodai
haodai@sh-135-haodai:/etc/mysql$ sudo service mysql start
sudo: unable to resolve host sh-135-haodai
mysql start/running, process 9143
haodai@sh-135-haodai:/etc/mysql$ sudo netstat -anpt | grep mysql
sudo: unable to resolve host sh-135-haodai
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      9143/mysqld     
haodai@sh-135-haodai:/etc/mysql$

5.2修改数据库方法(在mysql数据库的user表中添加host为%的数据即可)

二、mysql安装遇到问题

1.报错

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package mysql-server
E: Unable to locate package mysql-client

原因:数据源改变

解决:sudo apt-get update

注:sudo apt-get upgrade 是升级系统(慎用)

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值