Linux 安装MySQL
win 下的安装参考地址:https://www.cnblogs.com/miskis/p/5957091.html
卸载现有mysql重新安装参考地址:https://www.jianshu.com/p/7b8c4dea6829
获取最新的rpm地址:https://dev.mysql.com/downloads/repo/yum/
安装失败重新安装步骤,命令:
1、rpm -qa|grep mysql #找到已装的rpm包名
2、rpm -e 包名 #卸载
3、yum clean all #清缓存 关键!
安装配置
[root@iZ28gvqe4biZ ~]# rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm 获取http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm 准备中... ################################# [100%] 正在升级/安装... 1:mysql-community-release-el7-5 ################################# [100%]
这个时候查看当前可用的mysql安装资源:
[root@iZ28gvqe4biZ ~]# yum repolist enabled | grep "mysql.*-community.*" mysql-connectors-community/x86_64 MySQL Connectors Community 17 mysql-tools-community/x86_64 MySQL Tools Community 31 mysql56-community/x86_64 MySQL 5.6 Community Server 199
一般来说,只要安装mysql-server跟mysql-client
这个时候我们可以直接使用yum的方式安装MySQL了。
安装MySQL [root@iZ28gvqe4biZ ~]# yum -y install mysql-community-server 加入开机启动 [root@iZ28gvqe4biZ ~]# systemctl enable mysqld 启动mysql服务进程 [root@iZ28gvqe4biZ ~]# systemctl start mysqld
重置密码
[root@iZ28gvqe4biZ ~]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we'll need the current password for the root user. If you've just installed MySQL, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation. Set root password? [Y/n] y [设置root用户密码] New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y [删除匿名用户] ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] n [禁止root远程登录] ... skipping. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y [删除test数据库] - Dropping test database... ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist ... Failed! Not critical, keep moving... - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y [刷新权限] ... Success! All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL! Cleaning up...
MySQL相关操作
//登录MYSQL(有ROOT权限)。这里我以ROOT身份登录 [root@iZ28gvqe4biZ ~]# mysql -u root -p //首先为用户创建一个数据库hivemeta mysql > create database hivemeta; mysql > use hivemeta; //授权hdp用户拥有hivemeta数据库的所有权限。 mysql > grant all privileges on *.* to hdp@"%" identified by "hdp" with grant option; //刷新系统权限表 mysql > flush privileges; mysql > use hivemeta; //mysql/hive字符集问题 mysql > alter database hivemeta character set latin1;
连接时错误
如果你想连接你的mysql的时候发生这个错误:
ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL server
解决方法:
1。 改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"
//使用root登录mysql mysql -u root -p //切换数据库 mysql>use mysql; //修改数据 mysql>update user set host = '%' where user = 'root'; //查询数据 mysql>select host, user from user; //允许远程使用root账号登录 mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; //刷新权限 mysql>flush privileges;
windows 使用127.0.0.1 跟安装时的root账号密码连接数据库,连接成功后打开 名称为:mysql 的数据库中的 user 表 直接修改host 中 localhost 为% 在重启myql 服务进程就可以了
2. 授权法。例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
如果你想允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.10.40.54' IDENTIFIED BY '123456' WITH GRANT OPTION;
实例 允许所有用户使用 root账号 连接:GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
注:这样执行都需要逗号结束!