[root@CentOS61 ~]# yum install cmake nucrses-devel –y //安装编译环境及终端操作的开发包
……
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
检查mysql用户是否存在
[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
环境:CentOS6.7 Mysql5.6.35版本 Mysql数据库忘记root密码如何修改
登录Mysql数据库忘记密码
[root@CentOS61 ~]# mysql –V //查看mysql版本
mysql Ver 14.14 Distrib 5.6.35, for Linux (x86_64) using EditLine wrapper
[root@CentOS61 ~]# mysql -uroot –p //登录数据库
Enter password: //忘记密码
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@CentOS61 ~]# service mysqld stop
Shutting down MySQL.. SUCCESS!
[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> 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 //退出数据库
[root@CentOS61 ~]# pkill mysql //停止mysql数据库
[root@CentOS61 ~]# service mysqld start
Starting MySQL.. SUCCESS!
[root@CentOS61 ~]# mysql -uroot -p1234567 //使用新的密码重新登录数据库
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。