Linux系统下yum安装Mysql

/**温馨提示,该Linux操作系统为CentOS6.5版本的内核,不同Linux操作系统的内核可能有差别*/​​

1、删除系统自带的mysql

  • 一般Linux系统安装完毕都自带jdk与mysql,但并不是我们想要的版本,安装mysql之前,先将系统自带的mysql删除掉
/**查看系统上是否安装了mysql*/
# rpm -qa | grep mysql

/** 卸载系统自带的mysql,不建议使用yum remove去删除,yum会删除相关依赖,导致很多程序出错 */
# rpm -e --nodeps mysql-libs-5.1.71-1.el6.i686 

2、安装相关依赖

/** mysql的安装和运行需要相关的依赖,安装过程中,如果出现提示,一直 Y 即可 */
# yum install glibc.i686
# yum -y install libaio.so.1 libgcc_s.so.1 libstdc++.so.6
# yum install gcc-c++

3、下载yum源文件

/** 可以直接在mysql官网下载你所需要的yum源,上传到系统上去,或者使用wget在线下载 */
/** 下载mysql5.6 yum源 */
# wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm

4、安装yum源

/** 执行后,在/etc/yum.repos.d/ 这个目录下多出mysql-community-source.repo和mysql-community.repo 这两个文件*/
# rpm -ivh mysql-community-release-el6-5.noarch.rpm

5、安装mysql

/** 出现提示的话,一路 Y 到底 */
# yum install mysql-community-server

6、启动mysql服务

/** 启动mysql的服务 */
# service mysqld start

7、修改root用户密码

/** 由于mysql刚刚安装完的时候,mysql的root用户的密码默认是空的,当连接mysql提示输入密码时,直接回车即可*/
# mysql -u root -p

/** 此时已经连接上mysql了,mysql的用户名密码都存放在mysql库的user表中 */
# use mysql;
# update user set password=PASSWORD("这里输入root用户密码") where User='root';

/** 此时密码已经修改完毕,接着赋予root用户所有权限 */
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root用户密码' WITH GRANT OPTION;

/** 最后刷新权限 */
flush privileges;

/** 退出mysql,再次连接mysql的时候,就用刚刚设置的密码登入即可 */

8、设置开机自动启动

/** 执行完之后,每次重启系统之后,mysql服务也会自动启动,不需要每次都执行:service mysqld statr */
# chkconfig mysqld on

/** 至此,使用yum安装mysql就已经结束了 */

9、其它一些命令

/** 关闭mysql服务 */
# service mysqld stop
/** 重启mysql服务 */
# service mysqld restart
/** 查看mysql服务的状态 */
# service mysqld status

10、mysql安全设置

/**
 * 执行完该命令会进行以下几个操作:
 * --为root用户设置密码
 * --删除匿名账号
 * --取消root用户远程登录
 * --删除test库和对test库的访问权限
 * --刷新授权表使修改生效
 * 通过这几项的设置能够提高mysql库的安全。
 * 建议生产环境中mysql安装这完成后一定要运行一次,当然不运行也没有关系
 */

# mysql_secure_installation

[root@localhost ~]# 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]    #是否设置root用户密码,输入y并回车或直接回车
New password:               #设置root用户的密码
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]   #是否删除匿名用户,生产环境建议删除,所以直接回车
… 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] #是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止
… 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] #是否删除test数据库,直接回车
- 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] #是否重新加载权限表,直接回车
… 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!
[root@localhost ~]#

11、相关文件存放目录
 

/** mysql的配置文件,主要用于设置mysql端口,字符集,引擎等配置,对应于windows下my.ini */
# /etc/my.cnf

/** 存放数据库文件的目录 */
# /var/lib/mysql

/** 日志记录 */
# /var/log/ mysqld.log

/** socket文件 */
# var/run/mysqld/mysqld.pid

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值