centos系统安装mysql5.6

centos的版本是6.3, 要安装的mysql的版本是 mysql-5.6.26。系统本身没有安装mysql,没有旧版本。 虽然看起来蛮容易的,但是也比较容易出现各种错误,最重要还是耐心。

 

1、到官网下载安装安装文件mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz, glibc是已经编译好的安装文件

2、上传到centos,解压缩

      #tar -xzvf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz

3、安装 libaio

      #yum install libaio

4、拷贝解压的mysql文件

     #cd mysql-5.6.26-linux-glibc2.5-x86_64

     #mkdir /usr/local/mysql/

     #mv * /usr/local/mysql/

5、创建mysql用户

#groupadd mysql     #添加一个mysql用户组
#useradd -r -g mysql mysql

6、修改文件权限

#chown -R mysql:mysql  /usr/local/mysql

        不修改会报 权限不足错误

7、初始化数据库

 

# cd /usr/local/mysql/

#scripts/mysql_install_db  --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

8、启动数据库

#bin/mysqld_safe --user=mysql

 

1)如果出现Can't create/write to file '/var/run/mysqld/mysqld.pid 错误

 

ERROR] /usr/local/mysql/bin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file or directory)

2016-08-18 10:37:28 12334 [ERROR] Can't start server: can't create PID file: No such file or directory

 

执行以下语句:

 

#mkdir /var/run/mysqld

#chown -R mysql:mysql /var/run/mysqld

 

2)如果出现Table 'mysql.user' doesn't exist 错误

 

[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist

160818 10:41:36 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

 

请使用以下语句,重新初始化数据库:

 

#scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --ldata=/var/lib/mysql

 

9、设置root密码

先指定socket位置, 否则提示 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

#vim my.cnf

修改socket

 

socket=/tmp/mysql.sock

 

#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):<---输入现在的root密码,直接回车
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密码,当然设置了,输入Y回车

New password: <---输入root密码,并回车
Re-enter new password: <---再次输入root密码,并回车
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 <---是否删除匿名用户,删除,输入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 <---是否删禁止root用户远程登录,当然禁止,输入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] <---是否删除测试数据库test,删除,输入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 <---刷新权限,输入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!

 

至此,已经安装成功。

10、设置系统自动启动

# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

# chkconfig --add mysqld
# chkconfig --level 2345 mysqld on

 

11、添加环境变量

$vim /etc/profile

在最后添加

export MYSQL_HOME="/usr/local/mysql"
export PATH="$PATH:$MYSQL_HOME/bin"

 

刷新环境变量

 

$sudo source  /etc/profile

至此可以使用 service mysqld start | stop 来启停mysql 服务了。

 

12、最后,在 /usr/local/mysql下修改 my.cnf, (貌似不修改也没有问题)

在[mysqld]中添加或者修改一下内容:
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock

13、测试一下

       mysql -uroot -p

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值