您的位置:首页 > 数据库 > MySQL

mysql学习心得之二进制安装(4)

2016-01-03 16:12 232 查看

前序

mysql的安装方式有三种:1.rpm包安装。2.二进制安装。3.源代码编译安装。

之前已经用rpm包安装过了,这次用二进制安装的方式安装。

官方文档里面这样说的:

Oracle provides a set of binary distributions of MySQL. These include generic binary distributions in the form of compressed tar files (files with a .tar.gz extension) for a number of platforms, and binaries in platform-specific package formats for selected
platforms.

oracle提供了一系列的mysql的二进制文件。在压缩包内,它包括了一些普通的二进制文件以及一些所选平台特有的文件,这些文件在tar包中。

在安装之前,文档里面有几个小小的warning。

If you have previously installed MySQL using your operating system native package management system, such as yum or apt-get, you may experience problems installing using a native binary. Make sure your previous MySQL installation has been removed entirely
(using your package management system), and that any additional files, such as old versions of your data files, have also been removed. You should also check for configuration files such as /etc/my.cnf or the /etc/mysql directory and delete them.

如果你在你的系统中已经用了本地的包管理工具来安装的mysql,比如yum或者apt-get,你可能会经历一些问题。确保你之前的mysql安装已经完全的删除了。比如之前的数据文件的旧版本。而且你还得检查你的配置文件,比如/etc/my.cnf或者/etc/mysql目录并且删除他们。

MySQL has a dependency on the libaio library. Data directory initialization and subsequent server startup steps will fail if this library is not installed locally.If necessary, install it using the appropriate package manager. For example, on Yum-based systems:

shell> yum search libaio # search for info
shell> yum install libaio # install library


Or, on APT-based systems:

shell> apt-cache search libaio # search for info
shell> apt-get install libaio1 # install library


msql对libaio包也有依赖。如果这个包不安装的话,那么数据目录以及一些子进程的开启将会失败。

要使用mysql的二进制文件安装的话,那么你得使用如下的一些命令。

shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
# Next command is optional
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
这些命令假设你都是使用root用户登入系统的。以上都是官方文档里面的内容,我觉得在安装过程中的任何一个提示都得注意,不然就会掉入坑中。
下面是我根据官方文档具体的步骤做的一边,中间也加了几条文档没有的命令。

1.创建一个msql用户和用户组

如果你的系统还没有用户和用户组用来运行mysqld命令的话,你可能需要创建他们。下面的命令是用来增加一个mysql的用户组和mysql的用户。

[root@mysql ~]# groupadd mysql
[root@mysql ~]# useradd -r -g mysql -s /bin/false mysql


2.修改hosts文件

添加127.0.0.1 主机名到hosts文件中,不然安装会不成功。

3.获取并解压你的二进制安装包

选择一个目录你用来解压二进制包,并且帮当前路径换成该目录。举例,这里是使用了/usr/local。因此,假设你有权限在/usr/local这个目录创建文件或目录。
[root@SY local]# tar zxvf mysql-5.5.47-linux2.6-x86_64.tar.gz
[root@SY local]# ln -s mysql-5.5.47-linux2.6-x86_64 mysql

4.安装libaio.so包

[root@SY local]# rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm
warning: libaio-0.3.107-10.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Preparing...                ########################################### [100%]
1:libaio                 ########################################### [100%]

5.执行先前的操作

[root@SY local]# cd mysql
[root@SY mysql]# chown -R mysql .
[root@SY mysql]# chgrp -R mysql .
[root@SY mysql]# scripts/mysql_install_db --user=mysql
Installing MySQL system tables...
160104  1:26:08 [Note] ./bin/mysqld (mysqld 5.5.47) starting as process 1311 ...
OK
Filling help tables...
160104  1:26:08 [Note] ./bin/mysqld (mysqld 5.5.47) starting as process 1318 ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h SY password 'new-password'

Alternatively you can run:
./bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/ 
[root@SY mysql]# chown -R root .
[root@SY mysql]# chown -R mysql data
[root@SY mysql]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
[root@SY mysql]# cp support-files/my-medium.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'?
[root@SY mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@SY mysql]# ./bin/mysqld_safe --user=mysql
160104 01:29:56 mysqld_safe Logging to '/var/log/mysqld.log'.
160104 01:29:56 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
160104 01:29:57 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
[root@SY mysql]# ./bin/mysqladmin -u root password 123456
./bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
[root@SY mysql]# service mysqld start
Starting MySQL.. SUCCESS!
[root@SY mysql]# ./bin/mysqladmin -u root password 123456
[root@SY mysql]# ./bin/mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@SY mysql]# ./bin/mysql -u root -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.47 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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>
至此,安装就成功了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: