CentOS下安装mysql
课题组新买了一台阿里云服务器,今天安装了一下mysql,以后通过Navicat方便访问。
- 1、下载mysql的repo源
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
- 2、安装rpm包
rpm -ivh mysql-community-release-el7-5.noarch.rpm
- 3、安装mysql-server
sudo yum install mysql-server
- 4、测试是否安装成功
mysql -uroot -p
若进入mysql则安装成功。
- 5、修改root用户的密码
use mysql;
update user set password=password('new password') where user='root';
flush privileges;
出现的错误
(1)权限问题
- 错误提示
(ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2))
- 解决方法
sudo chown -R openscanner:openscanner /var/lib/mysql
//把这个文件的权限改为当前用户
- 错误提示
重启服务重新直接登录root用户 service mysqld restart mysql -u root
(2)登录问题
问题描述
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'
解决方案
1.关闭mysql
# service mysqld stop
2.屏蔽权限
# mysqld_safe --skip-grant-table
屏幕出现: Starting demo from .....
3.新开起一个终端输入
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;//记得要这句话,否则如果关闭先前的终端,又会出现原来的错误
mysql> \q
(3)远程访问
- 问题描述
ERROR 1130: Host '192.168.x.x' is not allowed to connect to thisMySQL server
解决方案
在安装mysql的机器上运行: mysql -u root -p mysql>usemysql; mysql>update user set host = '%' where user ='root'; mysql>select host, user from user; mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION //赋予任何主机访问数据的权限 mysql>FLUSH PRIVILEGES //修改生效 mysql>EXIT //退出MySQL服务器
- 问题描述