linux下安装mysql数据库5.6源码安装,修改登录用户密码

2019-11-20,,,,,

本篇内容主要给大家讲解一下如何在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

《linux下安装mysql数据库5.6源码安装,修改登录用户密码.doc》

下载本文的Word格式文档,以方便收藏与打印。