Linux上安装MySQL(CentOS)

本文详细介绍了MySQL5.6版本的下载、解压、安装及配置过程,包括用户组和用户的创建,依赖库的安装,服务的启动与停止,环境变量的设置,以及常见问题的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、下载

下载地址:http://dev.mysql.com/downloads/mysql/5.6.html#downloads

wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz

2、解压

tar -zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
cp -r mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql

3、添加用户组和用户

#添加用户组
groupadd mysql
#添加用户mysql 到用户组mysql
useradd -g mysql mysql

4、安装

yum -y install autoconf
yum install libaio* -y

cd /usr/local/mysql/
mkdir ./data/mysql
chown -R mysql:mysql ./
./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/mysql
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
cp support-files/my-default.cnf /etc/my.cnf

#修改启动脚本
vi /etc/init.d/mysqld
 
#修改项:
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/mysql


 
#启动服务
service mysqld start
 
#测试连接
./mysql/bin/mysql -uroot
 
#加入环境变量,编辑 /etc/profile,这样可以在任何地方用mysql命令了
export PATH=$PATH:/usr/local/mysql//bin
source /etc/profile
 
 
#启动mysql
service mysqld start
#关闭mysql
service mysqld stop
#查看运行状态
service mysqld status

修改用户密码

方式一:mysqladmin -uroot -p password '123456'
方式二:mysql> set password for root@localhost = password('123456');

5、Q&A

5.1 sqlyog连接时,报1130错误,是由于没有给远程连接的用户权限问题

 解决1:更改 ‘mysql’数据库‘user’表‘host’项,从‘localhost’改成‘%’。 

use mysql;
select 'host' from user where user='root'; 
update user set host = '%' where user ='root';
flush privileges; 

5.2 cannot open shared object file:

root@bigdata-159:/usr/local/mysql# ./bin/mysqld -- defaults-file=/etc/my.cnf --initialize --user=mysql
./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

yum install -y libaio  //安装后在初始化就OK了

5.3 密码错误,重置密码

vim /etc/my.cnf

在[mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证的过程

[mysqld]
skip-grant-tables
max_connections=5000

重启mysql服务并登录mysql

mysql> update user set password=password("newpassword") where user="root";
mysql> flush privileges;
mysql> quit

注意:如果在执行该步骤的时候出现ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement 错误。则执行下 flush privileges 命令,再执行该命令即可。

编辑my.cnf,去掉刚才添加的内容,然后重启MySQL。大功告成!

5.4 Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

yum -y install numactl

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值