1、Linux64位mysql下载
# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
2、解压安装包
# tar -xvf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
解压后的结果
# ls
mysql-8.0.18-linux-glibc2.12-x86_64 mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
3、将安装包移动到/usr/local/目录下,并重命名mysql
# mv mysql-8.0.18-linux-glibc2.12-x86_64 /usr/local/mysql
4、在mysql目录下创建data目录,存放数据
# cd /usr/local/mysql
# mkdir data
创建mysql用户组合mysql用户
# groupadd mysql
# useradd -g mysql mysql
5、改变mysql目录权限
# chown -R mysql.mysql /usr/local/mysql
6、初始化数据库
# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2020-01-03T03:18:55.148944Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-01-03T03:18:55.148978Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2020-01-03T03:18:55.149090Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.18) initializing of server in progress as process 15588
2020-01-03T03:19:00.601144Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: qj7Vc+-hyha/
7、配置mysql
在mysql/support-files创建文件my-default.cnf
[root@my ~]# cd /usr/local/mysql/support-files/
[root@my support-files]# touch my-default.cnf
复制配置文件到/etc/my.cnf
[root@iZ2ze6xk support-files]# cp -a ./my-default.cnf /etc/my.cnf
编辑 my.cnf
[root@localhost bin]# vi /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
#表名大小写不明感,敏感为
lower_case_table_names=1
8、配置mysql服务
[root@iZ2ze6Z etc]# cd /usr/local/mysql/
[root@iZ2ze6xk mysql]# cp -a ./support-files/mysql.server /etc/init.d/mysqld
[root@iZ2ze6x mysql]# chmod -x /etc/rc.d/init.d/mysqld
[root@iZ2ze6xk mysql]# chkconfig --add mysqld
#### 检查是否生效
[root@iZ2ze6xkq mysql]# chkconfig --list mysqld
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
9、配置环境变量
编辑 / etc/profile 文件
[root@my ~]# vi /etc/profile
在 profile 文件底部添加如下两行配置,保存后退出
PATH=/data/mysql/bin:/data/mysql/lib:$PATH
export PATH
设置环境变量立即生效
[root@my ~]source /etc/profile
10、启动mysql服务器
[root@localhost /]# /usr/local/mysql/support-files/mysql.server start
显示如下说明服务器安装成功:
Starting MySQL.Logging to '/usr/local/mysql/data/iZ2ze6xkq7xjxmfnsdw27yZ.err'.
.. [ OK ]
11、登录mysql,修改密码(密码为步骤6生成的临时密码,初始化数据库时的临时密码)
[root@localhost /]# mysql -u root -p
Enter password:
mysql> set password for root@localhost = 'yourpassword'
12、开放远程连接
mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;
示例:
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> update user set user.Host='%' where user.User='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
13、设置开机自动启动
1、将服务文件拷贝到init.d下,并重命名为mysql
[root@localhost /]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
2、赋予可执行权限
[root@localhost /]# chmod +x /etc/init.d/mysqld
3、添加服务
[root@localhost /]# chkconfig --add mysqld
4、显示服务列表
[root@localhost /]# chkconfig --list