码迷,mamicode.com
首页 > 数据库 > 详细

cenos安装MYSQL

时间:2017-11-21 22:10:10      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:原来   ##   root密码   登录   /usr   linux   mysq   mysql命令   from   

4.安装MySQL

[root@super ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.45-linux2.6-x86_64.tar.gz # 下载mysql 5.5 版本,下载过程比较漫长,需要的等待一下
[root@super ~]# tar xf mysql-5.5.45-linux2.6-x86_64.tar.gz -C /usr/local/ # 将mysql解压到 /usr/local/ 目录
[root@super local]# cd /usr/local/ # 进入该目录
[root@super local]# mv mysql-5.5.45-linux2.6-x86_64 mysql #重新命名mysql 这一步是必须的。
[root@super local]# groupadd -r -g 306 mysql #创建mysql用户组
[root@super local]# useradd -r -u 306 -g 306 -d /dev/null -s /sbin/nologin mysql #创建mysql用户
[root@super local]# tail -n 1 /etc/passwd #查看是否创建了mysql用户
mysql:x:306:306::/dev/null:/sbin/nologin
[root@super local]# chown -R mysql:mysql /usr/local/mysql/ # 给mysql目录下所有文件mysql拥有者和拥有组权限
[root@super local]# chmod -R 755 /usr/local/mysql/ # 给mysql目录下所有文件 755权限
################################  [root@super local]# mkdir /data # 创建数据库文件存放目录###########
################################[root@super local]# chown -R mysql:mysql /data/ # 给权限#################
[root@super mysql]# cd /usr/local/mysql/support-files/ 
[root@super support-files]# rpm -qa | grep mysql # 查看该系统mysql之前有没有装过
mysql-libs-5.1.71-1.el6.x86_64
[root@super support-files]# rpm -e --nodeps mysql-libs # 强制卸载该软件包
[root@super support-files]# cp -a mysql.server /etc/init.d/mysqld # 添加mysql服务到默认目录
[root@super support-files]# cp -a my-large.cnf /etc/my.cnf # 为mysql添加主配置文件
###################[root@super support-files]# vim /etc/my.cnf # 编辑mysql主配置文件###########################
#######################39 thread_concurrency = 2 39行,该参数是设置CPU个数,一般都是实际CPU个数*2###################
#########################40 datadir=/data 40行,该行为手动添加数据库文件存放目录#########################
#########################然后保存退出####################################
[root@super support-files]# cd .. # 退回上一级
[root@super mysql]# ./scripts/mysql_install_db --user=mysql # mysql初始化
注意:在初始化中有告警没关系,如果有报错请检查。
[root@super mysql]# service mysqld start
Starting MySQL.. [ OK ]

以上为正确启动了mysql

再使用ln -s /usr/local/mysql/bin/mysql /usr/bin 该命令边可以用mysql来进入进程
[root@super apache-tomcat-7.0.64]# chkconfig --add mysqld
[root@super apache-tomcat-7.0.64]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

将mysql添加为开机启动服务
[root@super ~]# vim /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don‘t
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
/bin/sh /usr/local/apache-tomcat-7.0.64/bin/startup.sh # 添加tomcat为开机启动

[root@super mysql]# vim /etc/profile.d/mysql.sh # 将mysql/bin目录添加到path环境变量这样方便执行mysql命令
export PATH=$PATH:/usr/local/mysql/bin
保存退出
[root@super mysql]# source /etc/profile.d/mysql.sh # 执行立即生效

[root@super ~]# vim /etc/sysconfig/iptables # 修改防火墙规则
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8009 -j ACCEPT
保存退出
[root@super ~]# service iptables restart # 重启生效

 

select host,user from user;
修改MYSQL密码
通过登录mysql系统,
# mysql -uroot -p
Enter password: 【输入原来的密码】
mysql>use mysql;
mysql> update user set password=passworD("test") where user=‘root‘;
mysql> flush privileges;
mysql> exit;

 

 

设置mysql控制台下密码
[html] view plain copy 在CODE上查看代码片派生到我的代码片


grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘123456‘ with grant option; 控制台密码


[html] view plain copy 在CODE上查看代码片派生到我的代码片
//root 是用户名,% 表示任意主机,‘123456‘ 指定的登录密码(这个和本地的root密码可以设置不同,互不影响)

[html] view plain copy 在CODE上查看代码片派生到我的代码片
flush privileges; //重载系统权限
[html] view plain copy 在CODE上查看代码片派生到我的代码片
exit;//退出mysql控制台

cenos安装MYSQL

标签:原来   ##   root密码   登录   /usr   linux   mysq   mysql命令   from   

原文地址:http://www.cnblogs.com/caizhichao/p/7875294.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!