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

来源:互联网 发布:linux操作系统入门书籍 编辑:程序博客网 时间:2024/05/29 18:55

前序

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

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

本次安装版本5.5.47,后面发现5.7的安装有了一定的变化,5.7.6之前和只有的安装步骤也有点不同。具体参考官方文档。

官方文档里面这样说的:

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 infoshell> yum install libaio # install library


Or, on APT-based systems:
shell> apt-cache search libaio # search for infoshell> apt-get install libaio1 # install library


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

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

shell> groupadd mysqlshell> useradd -r -g mysql -s /bin/false mysqlshell> cd /usr/localshell> tar zxvf /path/to/mysql-VERSION-OS.tar.gzshell> ln -s full-path-to-mysql-VERSION-OS mysqlshell> cd mysqlshell> chown -R mysql .shell> chgrp -R mysql .shell> scripts/mysql_install_db --user=mysqlshell> chown -R root .shell> chown -R mysql data# Next command is optionalshell> cp support-files/my-medium.cnf /etc/my.cnfshell> bin/mysqld_safe --user=mysql &# Next command is optionalshell> 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: NOKEYPreparing...                ########################################### [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=mysqlInstalling MySQL system tables...160104  1:26:08 [Note] ./bin/mysqld (mysqld 5.5.47) starting as process 1311 ...OKFilling help tables...160104  1:26:08 [Note] ./bin/mysqld (mysqld 5.5.47) starting as process 1318 ...OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE 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_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default.  This isstrongly 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.plcd ./mysql-test ; perl mysql-test-run.plPlease 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.cnfcp: overwrite `/etc/my.cnf'? [root@SY mysql]# cp support-files/mysql.server /etc/init.d/mysqld[root@SY mysql]# ./bin/mysqld_safe --user=mysql160104 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/mysql160104 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' failederror: '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 startStarting MySQL.. SUCCESS! [root@SY mysql]# ./bin/mysqladmin -u root password 123456[root@SY mysql]# ./bin/mysqlERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)[root@SY mysql]# ./bin/mysql -u root -p123456Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 3Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> 
至此,安装就成功了。




















0 0
原创粉丝点击