内容发布更新时间 : 2025/1/9 20:42:18星期一 下面是文章的全部内容请认真阅读。
Linux源码版mysql安装
1、保证机器安装了cmake编译工具 # yum install cmake -y
2、建立相应的用户和组 groupadd mysql
useradd -g mysql mysql
mysql用户和组:已经有就可以略掉
3、编译源码
# tar xvf mysql-5.5.25.tar.gz -C /opt # cd /opt/mysql-5.5.25/
# cmake . -LAH <---可选,用来查看当前源码编译的时候可以使用哪些编译参数 同样可以通过查看官档获取这些参数以及说明
需要包:yum -y install ncurses-devel
自定义安装参数
# cmake . -DCMAKE_INSTALL_PREFIX=/opt/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLED_LOCAL_INFILE=ON
(失败后重编译需删除CMakeCache.txt)
# make 根据配置文件进行编译
# make install 把编译好的文件安装到指定的安装目录
4、编写配置文件
# vim /opt/mysql/my.cnf [mysqld]
datadir=/opt/mysql/data user=mysql
socket=/opt/mysql/mysqld.sock skip-name-resolve port=3306
[mysqld_safe]
log-error=/opt/mysql/mysqld.err pid-file=/opt/mysql/mysqld.pid
5、初始化
mkdir /opt/mysql/data/&&mkdir /opt/mysql/logs chown mysql:mysql /opt/mysql/data chown mysql:mysql /opt/mysql/logs # cd /opt/mysql
指定初始化的数据库文件默认使用的字符集
# /opt/mysql/scripts/mysql_install_db --datadir=/opt/mysql/data
--basedir=/opt/mysql --user=mysql --collation_server=utf8_general_ci
若出现(Can't locate Data/Dumper.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5
/usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at scripts/mysql_install_db line 42.
BEGIN failed--compilation aborted at scripts/mysql_install_db line 42.)执行下面命令
yum install 'perl(Data::Dumper)'
6、启动并且修改密码
# /opt/mysql/bin/mysqld_safe --defaults-file=/opt/mysql/my.cnf -u mysql &
# /opt/mysql/bin/mysqladmin -u root -S /opt/mysql/data/mysql.sock password '123' # /opt/mysql/bin/mysqladmin -u root -h 127.0.0.1 -P 3306 password '123' 123为root密码,可自己修改