源码编译MysqL
[root@CentOS61 ~]# 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!
下载软件包
[root@CentOS61 ~]# 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上
解压
[root@CentOS61 ~]# tar -xf MysqL-5.6.35.tar.gz -C /usr/local/src/ //-C 指定解压目录
[root@CentOS61 ~]# ls /usr/local/src/
MysqL-5.6.35
[root@CentOS61 ~]# grep MysqL /etc/passwd
创建用户
[root@CentOS61 ~]# useradd -u 8001 -s /sbin/nologin MysqL
创建数据库目录
[root@CentOS61 ~]# mkdir /data
进入目录编译安装
[root@CentOS61 ~]# cd /usr/local/src/MysqL-5.6.35/
[root@CentOS61 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
开始编译并安装
[root@CentOS61 MysqL-5.6.35]# make -j 4 && make install
结束后使用$?查看是否成功
[root@CentOS61 MysqL-5.6.35]# echo $?
0
用户授权
[root@CentOS61 MysqL-5.6.35]# chown -R MysqL:MysqL /usr/local/MysqL
[root@CentOS61 MysqL-5.6.35]# chown -R MysqL:MysqL /data
[root@CentOS61 MysqL-5.6.35]# chmod 1777 /tmp/
创建配置文件
覆盖已有的配置文件
[root@CentOS61 MysqL-5.6.35]# cp /usr/local/MysqL/support-files/my-default.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'?y
设置环境变量
[root@CentOS61 MysqL-5.6.35]# echo 'export PATH=/usr/local/MysqL/bin:$PATH' >> /etc/profile
[root@CentOS61 MysqL-5.6.35]# source !$ //生效文件
source /etc/profile
创建服务启动脚本
[root@CentOS61 MysqL-5.6.35]# cp /usr/local/MysqL/support-files/MysqL.server /etc/init.d/MysqLd //复制启动脚本并重命名为MysqLd
[root@CentOS61 MysqL-5.6.35]# chmod +x !$
chmod +x /etc/init.d/MysqLd //赋予脚本执行权限
[root@CentOS61 ~]# vim /etc/init.d/MysqLd
46 basedir=
47 datadir=
为
46 basedir=/usr/local/MysqL
47 datadir=/data
设置开机自启动
[root@CentOS61 ~]# chkconfig MysqLd on //设置开机自启动
初始化数据库
[root@CentOS61 ~]# chmod +x /usr/local/MysqL/scripts/MysqL_install_db //给目录添加执行权限
[root@CentOS61 ~]# /usr/local/MysqL/scripts/MysqL_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/MysqL/ --datadir=/data/ --user=MysqL //指定配置文件、指定目录、指定用户(需要一点时间)
初始化安全配置
[root@CentOS61 ~]# service MysqLd start //启动服务
Starting MysqL.Logging to '/data/CentOS61.err'.
...................................................................................................................... SUCCESS!
注意:需要几分钟,可能是数据库版本问题
[root@CentOS61 ~]# service MysqLd status //查看服务状态
SUCCESS! MysqL running (16856)
[root@CentOS61 ~]# 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 //刷新数据库列表
登录数据库
[root@CentOS61 ~]# 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密码如何修改
[root@CentOS61 ~]# MysqL �CV //查看MysqL版本
MysqL Ver 14.14 Distrib 5.6.35,for Linux (x86_64) using EditLine wrapper
[root@CentOS61 ~]# MysqL -uroot �Cp //登录数据库
Enter password: //忘记密码
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
修改root密码
1、停止MysqL服务
[root@CentOS61 ~]# service MysqLd stop
Shutting down MysqL.. SUCCESS!
2、进入到skip-grant-tables模式
[root@CentOS61 ~]# 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
[root@CentOS61 ~]# 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; //刷新权限
[root@CentOS61 ~]# pkill MysqL //停止MysqL数据库
[root@CentOS61 ~]# service MysqLd start
Starting MysqL.. SUCCESS!
[root@CentOS61 ~]# MysqL -uroot -p1234567 //使用新的密码重新登录数据库
修改root密码成功