Mysql社区版的下载地址:
https://downloads.mysql.com/archives/community/
一般没有特殊要求,使用二进制包安装方法,就能满足大部分的场景需求
提示:
- 如果操作系统使用yum或apt安装了Mysql,使用二进制安装可以会有问题,所以安装前先删除。而且配置文件/etc/my.cnf或/etc/mysql目录也需要删除。
- 依赖libaio库
- Mysql5.7.19及更高版本,非统一内存访问(NUMA)的支持已经添加到通用包中,需要安装libnuma库
通用 Unix/Linux 二进制包的 MySQL 安装布局
目录 | 目录内容 |
---|---|
bin | mysqld服务、客户端和实用程序 |
docs | 信息格式的 MySQL 手册 |
man | Unix 手册页 |
includ | 包含(头)文件 |
lib | 库 |
share | 用于数据库安装的错误消息、字典和 Sql |
support-files | 其他支持文件 |
1.创建mysql用户和组
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
2.安装包解压
根据安装规范定义Mysql安装文件的位置
cd /usr/local
tar -zxvf /path/to/mysql-version-os.tar.gz
ln -s full-path-to-mysql-Version-os mysql
3.权限修改
mysql-files用于导入导出操作限制的特定目录。设置secure_file_priv系统环境变量使用
cd mysql
mkdir mysql-files
chmod 750 mysql-files
chown -R mysql .
chgrp -R mysql .
4.数据库的初始化
产生一些系统表空间,系统schema
bin/mysqld --initialize --user=mysql
bin/mysql_ssl_rsa_setup
[root@mysqldb mysql]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/mysqldata/3308/data
2021-12-22T15:32:48.661688Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-12-22T15:32:49.511155Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-12-22T15:32:49.704572Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-12-22T15:32:49.798083Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 6bb6ec76-633c-11ec-a581-000c2906f260.
2021-12-22T15:32:49.800217Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-12-22T15:32:49.801413Z 1 [Note] A temporary password is generated for root@localhost: phkCq(C.:7ps
[root@mysqldb mysql]#
[root@mysqldb mysql]# bin/mysql_ssl_rsa_setup --datadir=/mysqldata/3308/data/
Generating a 2048 bit RSA private key
.........+++
....................+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
....................+++
.............................................................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
...........................................................+++
..................................................................+++
writing new private key to 'client-key.pem'
-----
5.设置目录权限
chown -R root .
chown -R mysql data mysql-files
6.mysql的安全启动
bin/mysqld_safe --user=mysql &
7.加载环境变量
设置环境变量可以添加到.bash_profile中
export PATH=$PATH:/usr/local/mysql/bin
8.myql的登录需要首先修改密码
初始化换的时候会自动产生root的密码,首次登陆需要修改
mysql -uroot -pG498#dksf
mysql>set password=password('123')