一、首先到mysql的下载中心上下载最新的tar.gz包,网站:http://www.mysql.com/downloads/ mysql
二、下载后获得文件MySQL-5.5_mysql-5.5.34-linux2.6-i686.tar.gz,而后将其解压,并重命名为mysql,使用mv命令将其移到/usr/local目录下 linux
1 |
sudo mv ~/下载/mysql /usr/local |
提示:其中文本文件INSTALL-BINARY详细的记录了mysql在Linux下的安装方法,英文好的同鞋能够直接的查看
三、mysql默认的安装目录就是在/usr/local/mysql,这就是上面为何咱们要将其移动在/uer/local下的缘由;若是在你的机器上之前安装有老板本的mysql,须要先将它的文件删除,同时注意删除老板本的etc/my.cnf文件和/etc/mysql目录,这两个文件控制的是mysql的一些配置属性。
sql
四、先要建立的一个名为mysql的用户组和用户,来承载mysql数据库的运行,使用以下命令: 数据库
建立用户组: ubuntu
在建立的用户组中建立一个用户:
1 |
sudo useradd -r -g mysql mysql |
这里使用sudo命令是确保以root权限执行此命令,若是你登入本机的用户是root用户,则直接的使用groupadd和useradd命令
题外话:对应删除用户组及用户的命令是groupdel和userdel。 安全
五、接着进入mysql目录,修改mysql目录的拥有者,为mysql用户: socket
这里的点“.”表明的就是当前目录,选项-R表示递归当前目录及其子目录
六、安装mysql,执行命令: 网站
1 |
sudo scripts/mysql_install_db --user=mysql |
正确输出: spa
01 |
root@tianbaoxing-virtual-machine:/usr/local/mysql# sudo scripts/mysql_install_db --user=mysql |
02 |
Installing MySQL system tables... |
04 |
Filling help tables... |
07 |
To start mysqld at boot time you have to copy |
08 |
support-files/mysql.server to the right place for your system |
10 |
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! |
11 |
To do so, start the server, then issue the following commands: |
13 |
./bin/mysqladmin -u root password 'new-password' |
14 |
./bin/mysqladmin -u root -h tianbaoxing-virtual-machine password 'new-password' |
16 |
Alternatively you can run: |
17 |
./bin/mysql_secure_installation |
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. |
23 |
See the manual for more instructions. |
25 |
You can start the MySQL daemon with: |
26 |
cd . ; ./bin/mysqld_safe & |
28 |
You can test the MySQL daemon with mysql-test-run.pl |
29 |
cd ./mysql-test ; perl mysql-test-run.pl |
31 |
Please report any problems with the ./bin/mysqlbug script! |
注意:在Ubuntu 12.04下安装mysql 5.5.34版本执行此命令时,会提示以下错误的信息: .net
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的依赖库,执行以下命令:
安装共享库libaio1。在终端输入: sudo apt-get install libaio1
7/执行完上面的命令后,其实就已经完成了mysql的安装,但为了数据库的安全,能够将mysql目录的拥有者改成root用户,并将生成的系统依赖数据赋给mysql用户,执行以下命令:
8/安装好mysql后,就能够试着启动它,使用以下命令:
1 |
sudo ./support-files/mysql.server start |
一样重启和中止,只须要将上面命令的start改成restart或stop。
9/启动完mysql后,使用“./bin/mysql”命令来进入mysql数据库的控制台,执行SQL命令
结果:
01 |
mysql> show databases; |
02 |
+--------------------+ |
04 |
+--------------------+ |
05 |
| information_schema | |
07 |
| performance_schema | |
09 |
+--------------------+ |
10 |
4 rows in set (0.01 sec) |
十、修改mysql密码:
数据库初始密码是空的,设置密码:(注意因为数据库初始密码是空,因此Enter password:这一步时直接按回车建)
1 |
sudo ./bin/mysqladmin -u root -p password 'root' |
3 |
root@tianbaoxing-virtual-machine:/usr/local/mysql# |
设置这个密码命令,费了好大的力气,最后仍是查看安装mysql后输出的提示命令。
11/查看mysql版本:
guoyachao@ubuntu:/usr/local/mysql$ ./bin/mysqladmin -u root -p version Enter password:
./bin/mysqladmin Ver 8.42 Distrib 5.5.34, for linux2.6 on i686
Copyright (c) 2000, 2013, 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.
Server version 5.5.34
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /tmp/mysql.sock
Uptime: 13 min 38 sec
Threads: 1 Questions: 10 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables: 26 Queries per second avg: 0.012
文章借鉴于:http://www.linuxidc.com/Linux/2012-06/62458.htm;
来源于 http://my.oschina.net/winHerson/blog/112309