1.切换到src目录
cd /usr/local/src/
2. 下载mysql免编译二进制包
免编译的mysql二进制包5.6源码包:
wget http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
tar -zxvf http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
3. 把 mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz目录下所有文件 移到 /usr/local/mysql 位置
mv mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz/* /usr/local/mysql
4.建立MySql用户,因为启动MySQL需要改用户
useradd -s /sbin/nologin mysql
cd /usr/local/mysql
5.创建datadir,数据库文件会放到这里面
mkdir -p /data/mysql
6. 更改权限,不更改后续操作就会出问题
chown -R mysql:mysql /data/mysql
7. yum install libaio* -y
二进制安装mysql初始化出现:Installing MySQL system tables.../usr/local/mysql/bin/mysqld: error while loading shared
原因:缺少libaio库文件
解决方法:yum install libaio* -y
8. yum -y install numactl
bin/mysqld: error while loading shared libraries: libnuma.so.1: 安装mysql
如果安装mysql出现了以上的报错信息.这是却少numactl这个时候如果是Centos就yum -y install numactl就可以解决这个问题了.
ubuntu的就sudo apt-get install numactl就可以解决这个问题了
9. 编译安装
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
如果接下来你看到两个ok,并且会在/data/mysql目录下生成几个文件和目录,说明执行成功;或者在执行完成最后一条命令后,马上执行echo $? 看输出结果是否为0
10. 首先赋值配置文件,如下所示:
cp support-files/my-default.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
因为是系统默认就有/etc/my.cnf,所以会提示是否覆盖,直接按"y"即可,
11. 修改配置文件 ,如下所示:
vim /etc/my.cnf
---------------------------------------------------------------------------------------------------------------------------------------------
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
log_bin = ahui
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
server_id = 128
socket = /tmp/mysql.sock
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
----------------------------------------------------------------------------------------------------------------------
12. 然后复制启动脚本文件并修改其属性
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
13. 修改启动脚本
vim /etc/init.d/mysqld
需要修改的地方有 datadir=/data/mysql
14. 把启动脚本加入系统服务项,设定开机并启动mysql
a . 把mysqld服务加入到系统服务列表中,
chkconfig --add mysqld
b .使其开机就启动
chkconfig mysqld on
c .启动服务
service mysqld start
看见success,说明mysql已经启动成功了
15. 看看有没有监听3306端口
netstat -lnp|grep 3306
16.进入mysql
/usr/local/mysql/bin/mysql -u root
show databases;
17. Linux下修改Mysql的用户(root)的密码 (第一次进入需要密码,直接mysql -uroot -p 进来该密码)
通过登录mysql系统,
# mysql -uroot -p
Enter password: 【输入原来的密码】
mysql>use mysql;
mysql> update user set password=passworD("test") where user=‘root‘;
mysql> flush privileges;
mysql> exit;
原文地址:https://www.cnblogs.com/yehuisir/p/10061789.html