这里有新鲜出炉的 Linux 常用命令, 程序狗速度看过来!
Linux
Linux 是一套免费使用和自由传播的类 Unix 操作系统, 是一个基于 POSIX 和 UNIX 的多用户多任务支持多线程和多 CPU 的操作系统它能运行主要的 UNIX 工具软件应用程序和网络协议
这篇文章主要介绍了 linux 下安装 mysql5.6 版本并修改登录用户密码的方法
本篇内容主要给大家讲解一下如何在 linux 下安装 MYSQL 数据库, 并以安装 MYSQL5.6 版本为例子教给大家进行登录用户名和密码的修改等操作
源码下载地址 http://dev.mysql.com/downloads/mysql/5.6.html#downloads
tar.gz 地址: https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.37.tar.gz
选择 Generic Linux (Architecture Independent), Compressed TAR Archive
选择 No thanks, just start my download. 开始下载
操作系统:
centos6.5 x86_64
一 yum 安装相关依赖
# yum -y install gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake bison git openssl openssl-devel
二编译安装
1. 添加用户
- groupadd mysql
- useradd -r -g mysql mysql
2. 编译安装
- tar xf mysql-5.6.34.tar.gz
- cd mysql-5.6.34
- # 默认情况下是安装在 / usr/local/mysql
- # cmake 编译参数可以自己调整
- **************************************************************
- -- Looking for asprintf
- -- Looking for asprintf - found
- -- Check size of pthread_t
- -- Check size of pthread_t - done
- -- Using cmake version 2.8.12.2
- -- Not building NDB
- -- Performing Test HAVE_PEERCRED
- -- Performing Test HAVE_PEERCRED - Success
- -- Library mysqlclient depends on OSLIBS -lpthread;/usr/lib64/libz.so;m;rt;/usr/lib64/libssl.so;/usr/lib64/libcrypto.so;dl
- -- Googlemock was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source.
- -- If you are inside a firewall, you may need to use an http proxy: export http_proxy=http://example.com:80
- -- Library mysqlserver depends on OSLIBS -lpthread;/usr/lib64/libz.so;m;rt;/usr/lib64/libssl.so;/usr/lib64/libcrypto.so;dl;crypt
- -- CMAKE_BUILD_TYPE: RelWithDebInfo
- -- COMPILE_DEFINITIONS: HAVE_CONFIG_H
- -- CMAKE_C_FLAGS: -Wall -Wextra -Wformat-security -Wvla -Wwrite-strings -Wdeclaration-after-statement
- -- CMAKE_CXX_FLAGS: -Wall -Wextra -Wformat-security -Wvla -Woverloaded-virtual -Wno-unused-parameter
- -- CMAKE_C_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF
- -- CMAKE_CXX_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF
- -- Configuring done
- -- Generating done
- CMake Warning:
- Manually-specified variables were not used by the project:
- WITH_READLINE
- -- Build files have been written to: /root/mysql-5.6.34
- **************************************************************
cmake 编译报错需要删除编译缓存, 修复错误后再次重新编译
- rm -f CMakeCache.txt
- 3.make && make install
注意事项:
重新编译时, 需要清除旧的对象文件和缓存信息
- # make clean
- # rm -f CMakeCache.txt
- # rm -rf /etc/my.cnf
4. 改变数据存储目录所有者为 mysql
- chown -R mysql.mysql /usr/local/mysql
- chown -R mysql.mysql /data/mydata
5. 启动脚本初始化数据库
- cd /usr/local/mysql
- # scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mydata
6. 注册服务
- cp support-files/mysql.server /etc/rc.d/init.d/mysqld
- # 使用默认配置文件
- cp support-files/my-default.cnf /etc/my.cnf
- # 让 chkconfig 管理 mysql 服务
- chkconfig --add mysqld
- # 开机启动
- chkconfig mysqld on
编辑 vi /etc/my.cnf 配置, 加入以下内容
- innodb_file_per_table = 1
- datadir = /data/mydata
- log-bin=/data/binlogs/mysql-bin
注意:
经过实际测试 innodb_file_per_table = ON 这条参数需要 innodb_file_per_table = 1 才能生效, 具体可以通过
mysql> show variables like '%per_table%'; 来查询
- mkdir /data/binlogs
- chown -R mysql.mysql /data/binlogs
8. 将 mysql 命令加入环境变量中
vim /etc/profile.d/mysql.sh
加入
export PATH=/usr/local/mysql/bin:$PATH
默认密码为空
9 修改 vi /etc/security/limits.conf, 然后加入以下内容, 退出再重新登陆即可(不需要重启, 退出当前的连接 shell 即可)
- # ulimit -n 查看参数是否生效
- * hard nofile 655350
- * soft nofile 655350
否则报错如下:
错误 #23: Out of resources when opening file './XX/USER.MYD' (Errcode: 24)
同时
vim /etc/security/limits.d/90-nproc.conf
删除如下这行接触 centos 对文件操作句柄的限制:
* soft nproc 1024
关于 mysql 的启动和停止
- /etc/init.d/mysqld start
- /etc/init.d/mysqld stop
查看 mysql 是否已经启动成功
ps -elf |grep mysql |grep -v grep
更改允许 IP 访问(进入 mysql:2. 使用 mysql 库: 3. 查看用户表 :4. 更新用户表 :5. 强制刷新权限 :)
- /usr/local/mysql/bin/mysql -u root -p
- use mysql;
- SELECT `Host`,`User` FROM user;
- UPDATE user SET `Host` = '%' WHERE `User` = 'root' LIMIT 1;
- flush privileges;
更改 mysql 数据库登录用户密码 可使用 navcat 客户端连接进去更改登录用户的密码
# mysql -uroot -p
Enter password: 原始安装默认密码空直接回车
- mysql>use mysql;
- mysql> update user set password=passworD("root") where user='root';
- mysql> flush privileges;
- mysql> exit;
使用客户端连接测试之前一定要开放防火墙 3306 的连接端口
vi /etc/sysconfig/iptables
在 22 端口之后即可
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
重启防火墙即可生效
service iptables restart
来源: http://www.phperz.com/article/18/0225/361413.html