CentOS6.4安装MySql数据库

下载mysql的tar包

到mysql官网下载所需要版本的二进制包
mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz

创建安装目录并解压到安装目录

创建安装目录
mkdir /usr/local/mysql
解压到安装目录
tar -zxf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz -C /usr/local/mysql
剪切到解压后的mysql目录
mv /usr/local/mysql/mysql-5.6.35-linux-glibc2.5-x86_64/* /usr/local/mysql
删除解压的目录
rm -r /usr/local/mysql/mysql-5.6.35-linux-glibc2.5-x86_64

添加用户组和用户

添加用户组
groupadd mysql
添加用户mysql 到用户组mysql
useradd -mg mysql mysql


安装mysql

创建数据存放目录
mkdir -p /usr/local/mysql/data/
将安装目录赋给mysql用户
chown -R mysql:mysql /usr/local/mysql
执行安装脚本进行安装
cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/ --basedir=/usr/local/mysql
安装完成后拷贝mysqld
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
设置初始密码
/usr/local/mysql/bin/mysqladmin -u root password '123456'
查看安装日志找到你的cnf文件的位置并编辑
New default config file was created as/usr/local/mysql/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
vim /usr/local/mysql/my.cnf
socket =/var/lib/mysql/mysql.sock

修改启动脚本
vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

加入环境变量

这样就可以在任何地方用mysql命令了
vim /etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
然后刷新环境变量
source /etc/profile

服务及初始化配置

配置开机启动
chkconfig mysqld on
启动服务
service mysqld start
设置初始密码
mysql
set password=password("123456");
flush privileges;
测试连接
mysql -uroot -p123456
关闭mysql
service mysqld stop
查看运行状态
service mysqld status

你可能感兴趣的:(CentOS,MySql)