1.检查安装
rpm -qa | grep mysql --查看系统之前是否已安装MySQL。
2.删除这个老版本
rpm -e --nodeps mysql-libs-5.1.47-4.el6.i686
Rpm–qa | grep mariadb
删除mariadb
Rpm–e –nodeps mariadb名字
rpm -ivhmysql-community-common-5.7.16-1.el7.x86_64.rpm
rpm -ivhmysql-community-libs-5.7.16-1.el7.x86_64.rpm
rpm -ivhmysql-community-client-5.7.16-1.el7.x86_64.rpm
安装mysql-community-server-5.7.16-1.el7.x86_64.rpm 前需要安装libaio-0.3.107-10.el6.x86_66.rpm
下载地址:
http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm
安装libaio库:
rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm(若在有网情况下可执行yuminstall libaio)
安装mysql-community-server:
rpm -ivhmysql-community-server-5.7.16-1.el7.x86_64.rpm
mysql_install_db--datadir=/var/lib/mysql
Chown mysql:mysql /var/lib/mysql –R (手打)
10. 修改MySQL的登录设置:
# vim /etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables
例如:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
保存并且退出vi。
3.重新启动mysqld
# service mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
4.登录并修改MySQL的root密码
#mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 3.23.56
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>USE mysql ;
Database changed
mysql> UPDATE user SET Password = password ( 'new-password' )WHERE User = 'root' ;
(这句会出错说password不是一列,解决办法)
UPDATEuser SET authentication_string= password ( '123456' ) WHERE User ='root' ;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 0
mysql> flushprivileges ;
Query OK, 0 rows affected (0.01 sec)
mysql>quit
You mustreset your password using ALTER USER statement before。。。
Set password=password(‘123456’);(s大写)
http://blog.csdn.net/huwei2003/article/details/50945257
mysql -u root -p
use mysql;
select 'host' from user where user='root';
update user set host = '%' where user ='root';
flush privileges;
select 'host' from user whereuser='root';
SHOW VARIABLESLIKE ‘character%’;
修改mysql的 /etc/my.cnf 文件中的字符集键值(注意配置的字段细节):
[plain] view plain copy
1. 1、在[mysqld]字段里加入character-set-server=utf8,如下:
2.
3. [mysqld]
4. port = 3306
5. socket = /var/lib/mysql/mysql.sock
6. character-set-server=utf8
7.
重启mysql服务
我的mysql是部署在linux上的,修改/etc/my.cnf文件:
[html] view plain copy
1. sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER
解决CentOS7关闭/开启防火墙出现Unit iptables.service failed to load: No such file or directory
在CentOS 7或RHEL 7或Fedora中防火墙由firewalld来管理,
firewall-cmd –state 查看防火墙的状态
进入mysql数据库控制台,
如mysql-u root -p
mysql>use 数据库
然后使用source命令,后面参数为脚本文件(如这里用到的.sql)
mysql>source /home/soft/mysqlbak.sql
查看是否还有mysql软件:
rpm -qa|grep mysql
有的话继续删除
可以看到有两个安装包
MySQL-server-5.6.19-1.linux_glibc2.5.x86_64.rpm
MySQL-client-5.6.19-1.linux_glibc2.5.x86_64.rpm
删除这两个服务(去掉后缀)
rpm –e MySQL-client-5.6.19-1.linux_glibc2.5.x86_64
rpm -e MySQL-server-5.6.19-1.linux_glibc2.5.x86_64
查看残留的目录:
whereis mysql
然后删除mysql目录:
rm –rf /usr/lib64/mysql
删除相关文件:
rm –rf /usr/my.cnf
rm -rf /root/.mysql_sercret
最关键的:
rm -rf /var/lib/mysql
如果这个目录如果不删除,再重新安装之后,密码还是之前的密码,不会重新初始化!