Centos7.0下MySQL的安装
1.下载mysql的repo源
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
2.安装mysql-community-release-el7-5.noarch.rpm包
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
安装这个包后,会获得两个mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo。
3.安装mysql
sudo yum install mysql-server
根据提示安装就可以了,不过安装完成后没有密码,需要重置密码
4.重置mysql密码
mysql -u root
登录时有可能报这样的错:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2),原因是/var/lib/mysql的访问权限问题。下面的命令把/var/lib/mysql的拥有者改为当前用户:
sudo chown -R root:root /var/lib/mysql
重启mysql服务
service mysqld restart
接下来登录重置密码:
$ mysql -u root //直接回车进入mysql控制台 mysql > use mysql; mysql > update user set password=password('123456') where user='root'; mysql > FLUSH PRIVILEGES;
如果mysql -u root遇到/var/lib/mysql/mysql.sock错误的时候
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
远程使用workbench登录MySQL
mysql -u root -p #登录MySQL use mysql; #库 select host,user,password from user; #表中存放的是有访问权限的用户和ip grant all privileges on *.* to 'root'@'你的IP' identified by 'root' with grant option; # 添加用户,其中identified by 'root'中的root是'root'@'你的IP'这个用户登录时候使用的密码 flush privileges; set password for 'root'@'你的IP'=password('你的密码'); # 更改密码
本文只发表于博客园和tonglin0325的博客,作者:tonglin0325,转载请注明原文链接:https://www.cnblogs.com/tonglin0325/p/7910068.html