您的位置:首页 > 运维架构 > Linux

linux 下安装mysql

2014-04-22 14:28 411 查看


/////////////////////////////////////////////////////////阿里云centOS 6.5 安装mysql 默认版本,一般是5.1//////////////////////////////////////////////////////

#查看所有以mysql开头的软件
yum list mysql*

#安装mysql
yum install mysql-server* -y

#启动mysql
/etc/init.d/mysqld start

#设定mysql自动启动
chkconfig mysqld on

#用命令mysql
-u root -p
访问mysql ,重新设定mysql密码,默认密码是【空】,直接回车进入mysql

1 、mysql>show databases;

2、mysql>use mysql;

3、mysql> update user set password=password("123456")
where user='root';

4、mysql> flush
privileges;
5、mysql> exit; 
    

#设置远程访问权限

1、mysql> select Host ,User,Password from user;

2、mysql>delete from user where Host !='localhost';

3、mysql>update user set Host = '%';

4、mysql> exit; 
  


#重启mysql

 service mysqld stop

 service mysqld start

/////////////////////////////////////////////////////////阿里云centOS5.10安装mysql5.5//////////////////////////////////////////////////////

//一:安装

1、安装MySQL 5.5.x的yum源:

rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm
2、安装MySQL客户端的支持包:

yum install libmysqlclient15 --enablerepo=webtatic

3、卸载MySQL老版本的软件包:

yum remove mysql mysql-*

4、安装MySQL 5.5的客户端和服务端:

yum install mysql55 mysql55-server --enablerepo=webtatic

5、启动MySQL系统服务,更新数据库:

/etc/init.d/mysqld restart

mysql_upgrade

6、设置MySQL服务自启

chkconfig --levels 235 mysqld on

//二:mysql安全设置

1、设置(修改)root密码

2、删除匿名用户

3、禁用root远程登录

4、删除测试数据库test

5、重载权限表

要启用MySQL 安全设置请输入以下命令

/usr/bin/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  

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] Y  

 ... Success!  

   

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  

 - Dropping test database...  

 ... Success!  

 - 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!  

   

Cleaning up...  

   

   

   

All done!  If you\'ve completed all of the above steps, your MySQL  

installation should now be secure.  

   

Thanks for using MySQL!  

//三:设置mysql远程访问

使用mysql -hlocalhost -uroot -p 登入mysql 

1 、mysql>show databases;

2、mysql>use mysql;

3、mysql> select Host ,User,Password from user;

4、mysql>delete from user where Host !='localhost';

5、mysql>update user set Host = '%';

//四:重启mysql

 service mysqld stop

 service mysqld start

//五:配置防火墙开启3306端口

1. 修改/etc/sysconfig/iptables 文件:

vi /etc/sysconfig/iptables  

2. 在COMMIT之前加入以下内容:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT  

3. 重启Iptables:

service iptables restart  

## OR ##  

/etc/init.d/iptables restart  

4. 在客户机上测试远程访问数据库:

mysql -h dbserver_name_or_ip_address -u webdb_user -p webdb 

//六,拓展)为指定数据库,指定用户配置指定客户端(IP)远程访问

本示例的配置参数如下

DB_NAME = testdb

USER_NAME = testdb_user  

REMOTE_IP = 10.0.18.23  

PASSWORD = pwd321

PERMISSIONS = ALL  

1. 创建数据库 testdb

mysql> CREATE DATABASE testdb;  

2. 创建用户testdb_user

mysql> CREATE USER 'testdb_user'@'10.0.18.23' IDENTIFIED BY 'pwd321';  

3.  授权 

mysql> GRANT ALL ON testdb.* TO testdb_user@'10.0.18.23';  

4.  重载权限表  

mysql> FLUSH PRIVILEGES;  

====================yum源中没有mysql安装包的,按照下面方式安装,亲测,可用===========20161025=================

标签:

CentOS7的yum源中默认好像是没有mysql的。为了解决这个问题,我们要先下载mysql的repo源。

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 -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 openscanner:openscanner /var/lib/mysql


然后,重启服务:
service mysqld restart


接下来登录重置密码:
mysql -u root

mysql > use mysql;
mysql > update user set password=password(‘123456‘) where user=‘root‘;
mysql > exit;

设置mysql远程访问使用mysql -hlocalhost -uroot -p 登入mysql 
1 、mysql>show databases;2、mysql>use mysql;3、mysql> select Host ,User,Password from user;
4、mysql>delete from user where Host !='localhost';5、mysql>update user set Host = '%';6、mysql > exit;

5. 开放3306端口
sudo vim /etc/sysconfig/iptables


添加以下内容:
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT


保存后重启防火墙:
$ sudo service iptables restart


这样从其它客户机也可以连接上mysql服务了。

centos7下使用yum安装mysql
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: