【1】下载mysql.5.7.16-XXX.tar.gz
官网地址:https://downloads.mysql.com/archives/community/
这里可以选择任意版本以及操作系统。
编写脚本文件:mysql-5.7.16-install.sh。
脚本下载地址:http://download.csdn.net/download/j080624/10159581
【2】上传文件到服务器
如下图所示:
也可以使用wget命令从服务器直接下载:
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz
如下图所示,点击Download浏览器就会下载,只需要将下载的URL拼接到wget后面即可
【3】执行脚本文件
如上图所示,在/opt/soft/mysql5.7目录下,执行如下命令:
./mysql-5.7.16-install.sh
如果提示无权限,则执行如下命令:
chmod 755 ./mysql-5.7.16-install.sh
执行结果如下图:
最后一句表明,生成了临时默认密码,登录的时候需要使用。
【3】登录MySQL并修改密码
使用默认密码登录数据库,提示如下:
-- 启动mysql 服务 service mysqld start /usr/local/mysql/bin/mysql -u root -p //输入上面创建时生成的临时默认密码
修改密码:
mysql> alter user 'root'@'localhost' identified by '123456'; mysql> flush privileges; //或者如下 use mysql; UPDATE user SET Password=PASSWORD("123456") where USER='root';
再次查看数据库:
添加远程连接用户并赋予权限
mysql>use mysql; mysql> grant all on *.* to root@'%' identified by '123456' ; mysql>flush privileges;
如果发现有权限没有赋予,则使用如下:
GRANT Alter, Alter Routine, Create, Create Routine, Create Temporary Tables, Create User, Create View, Delete, Drop, Event, Execute, File, Grant Option, Index, Insert, Lock Tables, Process, References, Reload, Replication Client, Replication Slave, Select, Show Databases, Show View, Shutdown, Super, Trigger, Update ON *.* TO `root`@`%`;
如果不小心忘记默认登录密码,强力破解:http://blog.csdn.net/j080624/article/details/78286239
【4】给mysql添加软链
直接执行命令登录,提示如下:
mysql -u root -p -bash: /usr/bin/mysql: No such file or directory
//添加软链 [root@bogon MySQL]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql; //查看软链文件 [root@bogon MySQL]# ls -l /usr/bin/mysql; lrwxrwxrwx. 1 root root 26 Jul 3 02:28 /usr/bin/mysql -> /usr/local/mysql/bin/mysql //再次直接使用MySQL命令登录 [root@bogon MySQL]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.16 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> exit Bye