ubuntu安装mysql-5.5.28

 下面是我安装的步骤:

首先去官方下载tar包,100多M。

Linux下安装MySQL有三种方式:

 

第一种以rpm的二进制文件分个安装,

 

第二种是自己编译源码后安装,

 

第三种是以二进制tar.gz文件来安装

 

由于最后一种是统一的整体文件,故本文将采用此方式来进行安装

 

1、首先到mysql的下载中心上下载最新的tar.gz包,网站:http://www.mysql.com/downloads/

 

2、下载后得到文件mysql-5.6.10-linux-glibc2.5-i686.tar.gz,然后将其解压,并重命名为mysql,使用mv命令将其移到/usr/local目录下

 

 

 

1 sudo mv ~/下载/mysql  /usr/local

提示:其中文本文件INSTALL-BINARY详细的记录了mysql在Linux下的安装方法,英文好的同鞋可以直接的查看

 

 

3、mysql 默认的安装目录就是在/usr/local/mysql,这就是上面为什么我们要将其移动在/uer/local下的原因;如果在你的机器上以前安装有老 板本的mysql,需要先将它的文件删除,同时注意删除老板本的etc/my.cnf文件和/etc/mysql目录,这两个文件控制的是mysql的一 些配置属性。

 

4、先要创建的一个名为mysql的用户组和用户,来承载mysql数据库的运行,使用如下命令:

 

创建用户组:

 

 

 

1 sudo groupadd mysql

在创建的用户组中创建一个用户:

 

 

1 sudo useradd -r -g mysql mysql

这里使用sudo命令是确保以root权限执行此命令,如果你登入本机的用户是root用户,则直接的使用groupadd和useradd命令

题外话:对应删除用户组及用户的命令是groupdel和userdel。

 

5、接着进入mysql目录,修改mysql目录的拥有者,为mysql用户:

 

 

 

1 cd /usr/local/mysql
2 sudo chown -R mysql .
3 sudo chgrp -R mysql .

这里的点“.”代表的就是当前目录,选项-R表示递归当前目录及其子目录

6、安装mysql,执行命令:

 

 

 

1 sudo scripts/mysql_install_db --user=mysql

 

正确输出:

 

01 root@tianbaoxing-virtual-machine:/usr/local/mysql# sudo scripts/mysql_install_db --user=mysql
02 Installing MySQL system tables...
03 OK
04 Filling help tables...
05 OK
06  
07 To start mysqld at boot time you have to copy
08 support-files/mysql.server to the right place for your system
09  
10 PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
11 To do so, start the server, then issue the following commands:
12  
13 ./bin/mysqladmin -u root password 'new-password'
14 ./bin/mysqladmin -u root -h tianbaoxing-virtual-machine password 'new-password'
15  
16 Alternatively you can run:
17 ./bin/mysql_secure_installation
18  
19 which will also give you the option of removing the test
20 databases and anonymous user created by default.  This is
21 strongly recommended for production servers.
22  
23 See the manual for more instructions.
24  
25 You can start the MySQL daemon with:
26 cd . ; ./bin/mysqld_safe &
27  
28 You can test the MySQL daemon with mysql-test-run.pl
29 cd ./mysql-test ; perl mysql-test-run.pl
30  
31 Please report any problems with the ./bin/mysqlbug script!

 

 

 

注意:在Ubuntu 12.04下安装mysql 5.5.28版本执行此命令时,会提示如下错误的信息:

 

 

 

1 root@tianbaoxing-virtual-machine:/usr/local/mysql# sudo scripts/mysql_install_db  --user=mysql
2 Installing MySQL system tables..../bin/mysqld: error while loading shared libraries:
3 libaio.so.1: cannot open shared object file: No such file or directory

 

这说明还要安装一个libaio的依赖库,执行如下命令:

 

1 sudo apt-get install libaio-dev

当我执行上面的命令有报错错误2

1 root@tianbaoxing-virtual-machine:/usr/local/mysql# sudo apt-get install libaio-dev
2  
3 正在读取软件包列表... 有错误!
4 E: Encountered a section with no Package: header
5 E: Problem with MergeList /var/lib/apt/lists/cn.archive.ubuntu.com_ubuntu_dists_precise_main_i18n_Translation-en
6 E: 无法解析或打开软件包的列表或是状态文件。

 

解决:

 

提示的是上面的mirror站点的packages入口文件无法解析或打开.

 

 

 

我干脆就直接把lists文件夹里的文件全部删除掉, 然后再update一下就好了.

 

1 sudo rm -rf /var/lib/apt/lists/*
2 sudo apt-get update

 

7/执行完上面的命令后,其实就已经完成了mysql的安装,但为了数据库的安全,可以将mysql目录的拥有者改为root用户,并将生成的系统依赖数据赋给mysql用户,执行如下命令:

 

1 chown -R root .
2  
3 chown -R mysql data

8/安装好mysql后,就可以试着启动它,使用如下命令:

 

 

1 sudo ./support-files/mysql.server start

同样重启和停止,只需要将上面命令的start改为restart或stop。

9/启动完mysql后,使用“./bin/mysql”命令来进入mysql数据库的控制台,执行SQL命令

 

1 sudo show databases;

结果:

01 mysql>  show databases;
02 +--------------------+
03 | Database           |
04 +--------------------+
05 | information_schema |
06 | mysql              |
07 | performance_schema |
08 | test               |
09 +--------------------+
10 4 rows in set (0.01 sec)
11  
12 mysql>

 

10、修改mysql密码:

 

数据库初始密码是空的,设置密码:

 

1 sudo ./bin/mysqladmin -u root -p password 'root'
2 Enter password:
3 root@tianbaoxing-virtual-machine:/usr/local/mysql#

 

设置这个密码命令,费了好大的力气,最后还是查看安装mysql后输出的提示命令。

 

11/查看mysql版本:

 

01 root@tianbaoxing-virtual-machine:/usr/local/mysql# ./bin/mysqladmin -u root -p version
02 Enter password:
03 ./bin/mysqladmin  Ver 8.42 Distrib 5.5.28, for linux2.6 on i686
04 Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
05  
06 Oracle is a registered trademark of Oracle Corporation and/or its
07 affiliates. Other names may be trademarks of their respective
08 owners.
09  
10 Server version      5.5.28
11 Protocol version    10
12 Connection      Localhost via UNIX socket
13 UNIX socket     /tmp/mysql.sock
14 Uptime:         9 min 30 sec
15  
16 Threads: 1  Questions: 42  Slow queries: 0  Opens: 48  Flush tables: 1  Open tables: 41  Queries per second avg: 0.073

 

01 <p>
02 <span style="font-family:新細明體, serif;"><span style="font-size:small;">或者 在終端機使用指令</span></span>
03 </p>
04  
05 <p>
06 <span style="font-family:新細明體, serif;"><span style="font-size:small;">mysql --version</span></span>
07 </p>
08  
09 <p>
10 <span style="font-family:新細明體, serif;"><span style="font-size:small;">或者</span></span><span style="font-family:新細明體, serif;"><span style="font-size:small;">登錄 <span>mysql </span>用戶端後執行</span></span>
11 </p>
12  
13 <p>
14 <span style="font-family:新細明體, serif;"><span style="font-size:small;"></span></span>
15 </p>
16  
17 <p>
18 <span><span style="font-family:Calibri;">select version();</span></span><span style="font-family:'Courier New', Arial;font-size:9pt;line-height:1.5;"></span>
19 </p>

12/ 允许root远程登陆:

    1)本机登陆mysql:mysql -u root -p (-p一定要有);改变数据库:use mysql;

 

    2)从所有主机:grant all privileges on *.* to root@"%" identified by "passw0rd" with grant option;

 

    3)从指定主机:grant all privileges on *.* to root@"192.168.1.101" identified by "passw0rd" with grant option; flush privileges;

 

    4)  进mysql库查看host为%的数据是否添加:use mysql; select * from user;

 

打算指定特定主机登陆,根据第三条设置的,结果链接的时候报错

 

1 ERROR 1130 (HY000): Host '192.168.67.1' is not allowed to connect to this MySQL s
2 erver

而虚拟机的地址是192.168.67.23,怎么报连接不上192.168.67.1呢?应该还是权限没有设置好,我试了试:

1 grant all privileges on *.* to root@"192.168.67.1" identified by "root" with grant option; flush privileges

就好了,具体为什么,我没有想明白

 

修改密码

GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY “123456“;

bin/mysql -uroot -p123456

你可能感兴趣的:(mysql,安装,ubuntu,mysql-5.5.28)