mysql 开发进阶篇系列 29 数据库二进制包安装
概述
对于二进制安装,优点是可以安装到任何路径下,灵活性好,一台服务器可以安装多个mysql。缺点是已经绎过编译,性能不如源码编译得好,不能灵活定制编译参数。如果用户即不想安装最简单却不够灵活的rpm包,又不想安装复杂费时的源码包,那么已编译好的二进制包将是最好的选择。
一.步骤1: 解压glib包
-- 在 /usr/local 下创建一个mysql文件夹,用来存放 [root@hsr local]# mkdir mysql [root@hsr local]# ls bin etc games include lib lib64 libexec mysql sbin share src
-- 在原有/usr/tool目录将gz压缩包解压 [root@hsr tool]# tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz mysql-5.7.23-linux-glibc2.12-x86_64/bin/myisam_ftdump mysql-5.7.23-linux-glibc2.12-x86_64/bin/myisamchk mysql-5.7.23-linux-glibc2.12-x86_64/bin/myisamlog mysql-5.7.23-linux-glibc2.12-x86_64/bin/myisampack mysql-5.7.23-linux-glibc2.12-x86_64/bin/mysql mysql-5.7.23-linux-glibc2.12-x86_64/bin/mysql_client_test_embedded mysql-5.7.23-linux-glibc2.12-x86_64/bin/mysql_config_editor .....
--将解压的文件复制到/usr/local/mysql目录下 [root@hsr tool]# sudo cp -r mysql-5.7.23-linux-glibc2.12-x86_64 /usr/local/mysql
--在mysql-->mysql-5.7.23-linux-glibc2.12-x86_64路径下 解压的文件共9个 目录如下:
[root@hsr mysql]# ls mysql-5.7.23-linux-glibc2.12-x86_64 bin copying docs include lib man readme share support-files
注意:mysql-5.7.23-linux-glibc2.12-x86_64目录层次要去掉,变为/usr/local/mysql 下的9个目录,在文章后面会去掉这层。
二. 步骤2:
2.1 添加mysql用户 useradd -r -g 用户名 用户组
[root@hsr mysql]# groupadd mysql [root@hsr mysql]# useradd -r -g mysql mysql
2.2 切换到 /usr/local/mysql 目录下,改变目录拥有者为mysql
[root@hsr mysql]# chown -r mysql.mysql /usr/local/mysql
2.3 新环境安装libaio包 mysql 依赖于libaio
[root@hsr mysqld]# yum search libaio
三 步骤3:
安装mysql,使用 --initialize,basedir 基础目录,datadir 为数据目录。
[root@hsr ~]# cd /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/bin [root@hsr bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 2018-08-23t06:56:21.157088z 0 [warning] timestamp with implicit default value is deprecated. please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-08-23t06:56:21.157246z 0 [error] can't find error-message file '/usr/local/mysql/share/errmsg.sys'. check error-message file location and 'lc-messages-dir' configuration directive. 2018-08-23t06:56:26.287087z 0 [warning] innodb: new log files created, lsn=45790 2018-08-23t06:56:27.059913z 0 [warning] innodb: creating foreign key constraint system tables. 2018-08-23t06:56:27.138616z 0 [warning] no existing uuid has been found, so we assume that this is the first time that this server has been started. generating a new uuid: a7e28575-a6a1-11e8-af13-000c29affb65. 2018-08-23t06:56:27.154064z 0 [warning] gtid table is not ready to be used. table 'mysql.gtid_executed' cannot be opened. 2018-08-23t06:56:27.155635z 1 [note] a temporary password is generated for root@localhost: ro0ssogt?ocf
四步骤4:
4.1 创建rsa private key。
[root@hsr bin]# bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
4.2 修改当前目录拥有者为 root 用户,修改data 目录拥有者为 mysql
[root@hsr bin]# chown -r root:root /usr/local/mysql [root@hsr bin]# chown -r mysql:mysql /usr/local/mysql/data
五.步骤5 配置mysql(mysql.server)和my.cnf文件
--检查 etc/my.cnf文件是否存在 (二进制安装,默认配置文件在/etc/my.cnf) [root@hsr etc]# find -name my.cnf ./my.cnf
--将support-files 目录下的mysql.server文件复制到etc/init.d下 [root@hsr ~]# cd /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/support-files [root@hsr support-files]# cp mysql.server /etc/init.d/mysql
-- 配置/etc/init.d/mysql服务文件 添加basedir和datadir [root@hsr support-files]# vim /etc/init.d/mysql
修改my.cnf 配置以下四个参数(注意:chkconfig -- level 35 mysqld on 不要加上,后面报错,又得去掉)
六.步骤6 启动mysql
[root@hsr bin]# service mysql start /etc/init.d/mysql: line 239: my_print_defaults: command not found starting mysql error! couldn't find mysql server (/usr/local/mysql/bin/mysqld_safe) --提示未找到路径,需要把"mysql-5.7.23-linux-glibc2.12-x86_64" 文件夹去掉,使用mv 将里面的文件移到/usr/locl/mysql下,共9个文件 [root@hsr bin]# mv /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/readme /usr/local/mysql [root@hsr bin]# mv /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/copying /usr/local/mysql [root@hsr bin]# mv /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/support-files /usr/local/mysql [root@hsr bin]# mv /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/share /usr/local/mysql [root@hsr bin]# mv /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/man /usr/local/mysql [root@hsr bin]# mv /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/lib /usr/local/mysql [root@hsr bin]# mv /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/include /usr/local/mysql [root@hsr bin]# mv /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/docs /usr/local/mysql [root@hsr bin]# mv /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/bin /usr/local/mysql
-- 再启动 [root@hsr bin]# service mysql start starting mysql.2018-08-24t01:06:20.545225z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. create writable for user 'mysql'. error! the server quit without updating pid file (/usr/local/mysql/data/hsr.pid). -- 提示/var/log/mariadb/mariadb.log 不存在, 打开my.cnf 能看到定义的默认路径 [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid --创建目录 给权限 [root@hsr bin]# mkdir /var/log/mariadb [root@hsr bin]# touch /var/log/mariadb/mariadb.log [root@hsr bin]# chown -r mysql:mysql /var/log/mariadb/
-- 再启动 [root@hsr bin]# service mysql start starting mysql.... error! the server quit without updating pid file (/usr/local/mysql/data/hsr.pid). -- 错误信息是hsr.pid进程出问题,先查看下日志 [root@hsr ~]# cat /var/log/mariadb/mariadb.log
在my.cnf中注释上面参数(#chkconfig --level 35 mysqld on),再启动
上图意思是不能创建mysql.sock.lock 文件,一般是权限不足,如下设置好权限,启动成功
七 登录mysql
[root@hsr ~]# mysql -u root -p bash: mysql: 未找到命令
未找到命令,是由于系统默认会查找/usr/bin下的命令,如果这个命令不在这个目录下,就会找不到命令,需要映射一个链接到/usr/bin目录下,相当于建立一个链接文件。
[root@hsr ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin [root@hsr ~]# mysql -u -root -p error 2002 (hy000): can't connect to local mysql server through socket '/tmp/mysql.sock' (2) --错误信息是不能连接到本地的socket ,系统默认找到了/tmp目录下,需要设置链接文件 [root@hsr tmp]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
[root@hsr ~]# mysql -u -root -p enter password:
八. 设置密码
8.1 打开my.cnf文件,添加skip-grant-tables,来重置密码,如下所示
8.2 启动服务,再次登录,在输入密码处按回车键进入。
[root@hsr ~]# vim /etc/my.cnf [root@hsr ~]# service mysql restart shutting down mysql.. success! starting mysql. success! [root@hsr ~]# mysql -u root -p enter password: welcome to the mysql monitor. commands end with ; or \g. your mysql connection id is 2 server version: 5.7.23
8.3 进入mysql后,修改密码
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> update user set authentication_string=password('123456') where user='root'; query ok, 1 row affected, 1 warning (0.00 sec) rows matched: 1 changed: 1 warnings: 1
退出mysql>quit; 编辑 my.cnf 注释掉#skip-grant-tables
8.4 重启mysql服务,输入修改后的密码(123456)进入
[root@hsr ~]# service mysql restart shutting down mysql.. success! starting mysql. success! [root@hsr ~]# mysql -u root -p enter password: welcome to the mysql monitor. commands end with ; or \g. your mysql connection id is 2 server version: 5.7.23
九 远程登录
-- 登录到mysql后设置权限 mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option; error 1820 (hy000): you must reset your password using alter user statement before executing this statement. -- 再设置密码 mysql> set password = password('123456'); query ok, 0 rows affected, 1 warning (0.00 sec) -- 设置权限 mysql> alter user 'root'@'localhost' password expire never; query ok, 0 rows affected (0.00 sec) -- 刷新权限 mysql> flush privileges; query ok, 0 rows affected (0.01 sec) -- 设置远程登录权限 mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option; query ok, 0 rows affected, 1 warning (0.00 sec)
-- 在my.cnf中 添加端口,重启服务
-- 测试端口是否打开 [root@hsr ~]# firewall-cmd --query-port=3306/tcp no -- 防火墙设置 [root@hsr ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent success -- 重新加载 [root@hsr ~]# firewall-cmd --reload success -- 再次测试端口 [root@hsr ~]# firewall-cmd --query-port=3306/tcp yes
-- 在windows端拼通成功
--- 最后使用sqlyog连接成功
上一篇: Fireworks教程:美女照片超绚背景
下一篇: 如何修改数据库密码
推荐阅读
-
mysql 开发进阶篇系列30 数据库二进制包(安装指定路径,目录介绍)
-
mysql 开发进阶篇系列 25 数据库RPM安装目录介绍
-
mysql 开发进阶篇系列 40 mysql日志之二进制日志下以及查询日志
-
mysql 开发进阶篇系列 29 数据库二进制包安装
-
mysql 开发进阶篇系列 39 mysql日志之二进制日志(binlog)
-
mysql 开发进阶篇系列 36 工具篇mysqlshow(数据库对象查看工具)
-
mysql 开发进阶篇系列 27 数据库字符集设置
-
mysql 开发进阶篇系列30 数据库二进制包(安装指定路径,目录介绍)
-
mysql 开发进阶篇系列 39 mysql日志之二进制日志(binlog)
-
mysql 开发进阶篇系列 25 数据库RPM安装目录介绍