linux mysql5.6.35_CentOS6.7 Mysql5.6.35版本 源码编译+Mysql数据库忘记root密码如何修改...

源码编译MySQL

[[email protected] ~]# yum install cmake nucrses-devel �Cy      //安装编译环境及终端操作的开发包

……

Installed:

cmake.x86_64 0:2.8.12.2-4.el6

Dependency Installed:

libarchive.x86_64 0:2.8.3-7.el6_8

Complete!

下载软件包

[[email protected] ~]# wget http://ftp.ntu.edu.tw/pub/MySQL/Downloads/MySQL-5.6/mysql-5.6.35.tar.gz

。。。。。。

100%[+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>] 32,167,628  24.0K/s   in 2.2s

2017-04-12 22:23:19 (24.0 KB/s) - “mysql-5.6.35.tar.gz” saved [32167628/32167628]

注意:如果命令下载较慢的话,可以使用windows下载后再传到Linux上

解压

[[email protected] ~]# tar -xf mysql-5.6.35.tar.gz -C /usr/local/src/        //-C 指定解压目录

[[email protected] ~]# ls /usr/local/src/

mysql-5.6.35

检查mysql用户是否存在

[[email protected] ~]# grep mysql /etc/passwd

创建用户

[[email protected] ~]# useradd -u 8001 -s /sbin/nologin mysql

创建数据库目录

进入目录编译安装

[[email protected] ~]# cd /usr/local/src/mysql-5.6.35/

[[email protected] mysql-5.6.35]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data -DMYSQL_USER=mysql

开始编译并安装

[[email protected] mysql-5.6.35]# make -j 4 && make install

结束后使用$?查看是否成功

[[email protected] mysql-5.6.35]# echo $?

0

用户授权

[[email protected] mysql-5.6.35]# chown -R mysql:mysql /usr/local/mysql

[[email protected] mysql-5.6.35]# chown -R mysql:mysql /data

[[email protected] mysql-5.6.35]# chmod 1777 /tmp/

创建配置文件

覆盖已有的配置文件

[[email protected] mysql-5.6.35]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

cp: overwrite `/etc/my.cnf'? y

设置环境变量

[[email protected] mysql-5.6.35]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile

[[email protected] mysql-5.6.35]# source !$             //生效文件

source /etc/profile

创建服务启动脚本

[[email protected] mysql-5.6.35]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld           //复制启动脚本并重命名为mysqld

[[email protected] mysql-5.6.35]# chmod +x !$

chmod +x /etc/init.d/mysqld            //赋予脚本执行权限

[[email protected] ~]# vim /etc/init.d/mysqld

修改

46 basedir=

47 datadir=

46 basedir=/usr/local/mysql

47 datadir=/data

设置开机自启动

[[email protected] ~]# chkconfig mysqld on               //设置开机自启动

初始化数据库

[[email protected] ~]# chmod +x /usr/local/mysql/scripts/mysql_install_db          //给目录添加执行权限

[[email protected] ~]# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/ --user=mysql                    //指定配置文件、指定目录、指定用户(需要一点时间)

初始化安全配置

[[email protected] ~]# service mysqld start               //启动服务

Starting MySQL.Logging to '/data/CentOS61.err'.

...................................................................................................................... SUCCESS!

注意:需要几分钟,可能是数据库版本问题

[[email protected] ~]# service mysqld status            //查看服务状态

SUCCESS! MySQL running (16856)

[[email protected] ~]# mysql_secure_installation

……

Enter current password for root (enter for none):         //要求输入密码,没有密码直接回车

……

Set root password? [Y/n] Y                //提示设置root密码

New password:                //输入要设置的密码123456(密文显示)

Re-enter new password:                  //重复确认密码

……

Remove anonymous users? [Y/n] y //是否删除匿名用户(匿名用户可登录服务器,需要删除)

......

Disallow root login remotely? [Y/n] Y      //禁止root用户远程登录

……

Remove test database and access to it? [Y/n] Y     //删除测试数据库(创建好数据库,测试数据库就没用了)

……

Reload privilege tables now? [Y/n] Y        //刷新数据库列表

登录数据库

[[email protected] ~]# mysql -u root -p123456          //登录数据库

mysql> show engines;     //查看默认引擎

+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+

| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |

+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+

| FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |

| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |

| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |

| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |

| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |

| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |

| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |

| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |

| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |

+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+

9 rows in set (0.00 sec)

安装MySQL Complete

Mysql数据库忘记root密码如何修改

环境:CentOS6.7   Mysql5.6.35版本 Mysql数据库忘记root密码如何修改

登录Mysql数据库忘记密码

[[email protected] ~]# mysql �CV        //查看mysql版本

mysql  Ver 14.14 Distrib 5.6.35, for Linux (x86_64) using  EditLine wrapper

[[email protected] ~]# mysql -uroot �Cp     //登录数据库

Enter password:    //忘记密码

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

修改root密码

1、停止mysql服务

[[email protected] ~]# service mysqld stop

Shutting down MySQL.. SUCCESS!

2、进入到skip-grant-tables模式

[[email protected] ~]# mysqld_safe --skip-grant-tables

170413 01:51:11 mysqld_safe Logging to '/data/CentOS61.err'.

170413 01:51:11 mysqld_safe Starting mysqld daemon with databases from /data

Ctrl+z  重新设置好root密码后终止

[1]+  Stopped                 mysqld_safe --skip-grant-tables

新开一个窗口登录数据库,可以跳过密码认证

[[email protected] ~]# mysql     //直接进入数据库

mysql> use mysql    //进入mysql数据库

mysql> update user set password=password("1234567") where user="root";    //修改root密码

Query OK, 3 rows affected (0.00 sec)

Rows matched: 3  Changed: 3  Warnings: 0

mysql> flush privileges;            //刷新权限

Query OK, 0 rows affected (0.01 sec)

mysql> exit       //退出数据库

[[email protected] ~]# pkill mysql      //停止mysql数据库

[[email protected] ~]# service mysqld start

Starting MySQL.. SUCCESS!

[[email protected] ~]# mysql -uroot -p1234567        //使用新的密码重新登录数据库

修改root密码成功

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值