linux7编译安装mysql8.0

系统版本信息

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 

安装依赖包

[root@localhost ~]# yum -y install wget cmake gcc gcc-c++ ncurses ncurses-devel libaio-devel openssl openssl-devel
[root@localhost ~]# rpm -qa |grep libaio
libaio-devel-0.3.109-13.el7.x86_64
libaio-0.3.109-13.el7.x86_64

#要是没有安装就要安装一下

[root@localhost ~]# yum install libaio libaio-devel

下载源码包

[root@localhost ~]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.12.tar.gz

创建用户和建立数据目录并赋予用户目录权限

[root@localhost ~]# useradd -r -g mysql -s /sbin/nologin mysql
[root@localhost ~]# mkdir -p /usr/local/mysql
[root@localhost ~]# mkdir -p /usr/local/mysql/data
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql/*
[root@localhost ~]# chmod -R 755 /usr/local/mysql/

解压并安装

[root@localhost ~]# tar -xf mysql-boost-8.0.12.tar.gz

配置

[root@localhost ~]# cd mysql-8.0.12
[root@localhost mysql-8.0.12]#cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DMYSQL_TCP_PORT=3306 \
-DWITH_BOOST=~/mysql-8.0.12/boost \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNODB_MEMCACHED=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1

配置参数说明:
CMAKE_INSTALL_PREFIX :指定基础安装目录
MYSQL_DATADIR :指定数据目录
SYSCONFDIR=/etc :指定配置文件扫描目录
MYSQL_TCP_PORT :指定端口号
WITH_BOOST :指定boost所在目录
DEFAULT_CHARSET :指定默认字符集
DEFAULT_COLLATION :指定默认排序规则
ENABLED_LOCAL_INFILE=ON :是否为load data infile启用local
WITH_INNODB_MEMCACHED=ON :是否生成memcached共享库

编译&安装

[root@localhost mysql-8.0.12]#make && make install 

需要一点时间(看配置,配置低需要的时间比较长)

配置环境变量

echo "PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
source /etc/profile

初始化数据库

[root@localhost mysql-8.0.12]#mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

建立配置文件

cat > /etc/my.cnf <<EOF
[client]
port=3306
socket=/tmp/mysql.sock
default-character-set=utf8
#user=root
#password=123
[mysqld]
server-id=1
#skip-grant-tables
port=3306
user=mysql
max_connections=200
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
pid-file=/usr/local/mysql/data/mysql.pid
init-connect='SET NAMES utf8'
character-set-server=utf8
default-storage-engine=INNODB
log_error=/usr/local/mysql/data/mysql-error.log
slow_query_log_file=/usr/local/mysql/data/mysql-slow.log
[mysqldump]
quick
max_allowed_packet=16M
EOF

配置启动脚本

[root@localhost mysql-8.0.12]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql-8.0.12]# vim /etc/init.d/mysqld


修改
安装路径
basedir=/usr/local/mysql
数据库文件存放路径
datadir=/usr/local/mysql/data

修改启动脚本权限

[root@localhost mysql-8.0.12]# chmod +x /etc/init.d/mysqld 

启动服务

[root@localhost mysql-8.0.12]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/mysql-error.log'.
 SUCCESS! 

centos7系统自启动脚本(可以忽略)

cat /usr/lib/systemd/system/mysqld.service
[Unit]
Description=mysql server daemon
Documentation=man:mysql(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=notify
TimeoutSec=0
PermissionsStartOnly=true
ExecStart=/usr/local/mysql/bin/mysqld $MYSQLD_OPTS
LimitNOFILE = 10000
Restart=always
RestartPreventExitStatus=1
Environment=MYSQLD_PARENT_PID=1
PrivateTmp=false

启动MySQL
systemctl start mysqld.service

修改root密码:使用WITH指定认证方式

[root@localhost mysql-8.0.12]#mysql -uroot
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';

ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH caching_sha2_password BY ‘你的密码’;

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY'123456';
Query OK, 0 rows affected (0.03 sec)

mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH caching_sha2_password BY ‘123456’;
Query OK, 0 rows affected (0.04 sec)

刷新权限

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

查看密码字段和加密方式

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host,user,authentication_string,plugin from user;

安装完毕

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Sure! Here are the steps to compile and install MySQL 8.0 on Linux: 1. Download the MySQL source code from the MySQL website. Make sure to choose the appropriate package for your Linux distribution. 2. Install the necessary dependencies. This may vary depending on your Linux distribution, but typically, you will need packages like `build-essential`, `cmake`, `libssl-dev`, `libncurses5-dev`, `libboost-dev`, etc. You can use your package manager (e.g., apt-get, yum) to install them. 3. Extract the downloaded MySQL source code package. 4. Create a build directory and navigate into it: ``` mkdir mysql-build cd mysql-build ``` 5. Configure the build using cmake. Replace `<path-to-source-directory>` with the path to the extracted MySQL source code: ``` cmake <path-to-source-directory> ``` 6. Build MySQL using make: ``` make ``` 7. Install MySQL: ``` sudo make install ``` 8. Initialize the MySQL data directory: ``` sudo mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data ``` 9. Set the ownership and permissions for the MySQL data directory: ``` sudo chown -R mysql:mysql /usr/local/mysql/data sudo chmod -R 750 /usr/local/mysql/data ``` 10. Start the MySQL server: ``` sudo /usr/local/mysql/support-files/mysql.server start ``` 11. Secure the installation by running the MySQL secure installation script: ``` sudo mysql_secure_installation ``` 12. Follow the prompts to set a root password, remove anonymous users, disable remote root login, etc. That's it! You have successfully compiled and installed MySQL 8.0 on your Linux system.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Rio520

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值