欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-06-24 13:42:13
本篇内容主要给大家讲解一下如何在linux下安装mysql数据库,并以安装mysql5.6版本为例子教给大家进行登录用户名和密码的修改等操作。 源码下载地址http://...

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

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

选择generic linux (architecture independent), compressed tar archive

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

选择 no thanks, just start my download. 开始下载

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

操作系统:

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