安装mysql时候找不到密码尝试无果后开始卸载重装
create database testdb; create user 'testuser'@'localhost' identified by 'password'; grant all on testdb.* to 'testuser' identified by 'password';
sudo yum update:更新yum软件 yum update -y 不用按确定一直跟新的 rpm -e 软件包:卸载软件包
rpm -e --nodeps:强制卸载
查看mysql的安装情况
rpm -qa | grep -i mysq
卸载:
1.普通卸载(可能有依赖关系)
rpm -e mysql-community-libs-5.7.18-1.el6.x86_64
2.强制卸载
rpm -e --nodeps mysql-community-libs-5.7.18-1.el6.x86_64
删除mysql服务
[root@localhost local]# chkconfig --list | grep -i mysql [root@localhost local]# chkconfig --del mysql
在Linux系统下,通过命令“rm -rf”可以将任何数据直接从硬盘删除,并且没有任何提示
删除分散mysql文件夹
[root@localhost local]# whereis mysql 或者 find / -name mysql
mysql: /usr/lib/mysql /usr/share/mysql
清空相关mysql的所有目录以及文件 rm -rf /usr/lib/mysql rm -rf /usr/share/mysql
rm -rf /usr/my.cnf
下面成功安装mysql服务详细步骤
1.Update your system:
sudo yum update 2. Install and Start MySQL
(1)Install MySQL and tell it which runlevels to start on:
sudo yum install mysql-server sudo /sbin/chkconfig --levels 235 mysqld on (2) Then to start the MySQL server:
sudo service mysqld start 3.set password
sudo mysql_secure_installation 回车,回车跳过初始密码
设置新的密码
4.登录mysql
mysql -u root -p
In the example below, testdb is the name of the database, testuser is the user, and passwordis the user’s password.
create database testdb; create user 'testuser'@'localhost' identified by 'password'; grant all on testdb.* to 'testuser' identified by 'password';You can shorten this process by creating the user while assigning database permissions:
create database testdb; grant all on testdb.* to 'testuser' identified by 'password';
Then exit MySQL.
重置密码:
If you forget your root MySQL password, it can be flushed and then reset.
Stop the current MySQL server instance, then restart it with an option to not ask for a password.
sudo /etc/init.d/mysqld stop sudo mysqld_safe --skip-grant-tables & Reconnect to the MySQL server with the MySQL root account.mysql -u root
Use the following commands to reset root’s password. Replace password with a strong password.
use mysql; update user SET PASSWORD=PASSWORD("password") WHERE USER='root'; flush privileges; exit Then restart MySQL.
sudo service mysqld restart
关于数据库乱码问题:
查看数据库字符集
SHOW VARIABLES LIKE 'character%';
上面是正确的编码
刚开始可能是latint1,全部修改成你需要的编码
#vim /etc/mysql/my.cnf (5.5以前系统)如下修改:
在【client】下面加入 default-character-set=utf8
在【mysqld】下面加入default-character-set=utf8
Notice:注意 如果修改后不能启动报错试试把default-character-set=utf8改为character_set_server=utf8,仅仅加入到mysqld下面的.client就不需要加了
#vim /etc/mysql/my.cnf 。(5.5以后系统)如下修改:
[client] default-character-set=utf8
[mysqld] default-storage-engine=INNODB character-set-server=utf8 collation-server=utf8_general_ci
卸载:参考:http://blog.csdn.net/rosten/article/details/25096159
安装:参考:https://www.linode.com/docs/databases/mysql/how-to-install-mysql-on-centos-6