Mysql安装
服务名称 | 版本 | 主机IP地址 | 用户名 | 密码 |
---|---|---|---|---|
mysql | 5.7.18 | 10.1.1.101 | mysql | password |
MYSQ安装包地址:https://downloads.mysql.com/archives/community/
注:所有安装包都在/h3cu下
-
查询虚拟机是否安装了mariadb
[root@localhost ~]# rpm -qa | grep mariadb mariadb-libs-5.5.44-2.el7.centos.x86_64
-
卸载mariadb
[root@localhost ~]# rpm -e --nodeps mariadb-libs [root@localhost ~]# rpm -qa | grep mariadb [root@localhost ~]#
-
将/h3cu下面的mysql安装到/usr/local下
[root@localhost ~]# tar -xzf /h3cu/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
-
查看路径下的文件
[root@localhost ~]# ls /usr/local/ | grep mysql mysql-5.7.18-linux-glibc2.5-x86_64
-
将解压后的文件重命名为mysql目录
[root@localhost ~]# mv /usr/local/mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/mysql [root@localhost ~]# ll /usr/local | grep mysql drwxr-xr-x. 9 root root 4096 Jun 19 06:51 mysql
-
创建mysql用户和组
[root@localhost ~]# groupadd mysql [root@localhost ~]# useradd -r -g mysql mysql
-
创建mysql数据文件和临时文件目录
[root@localhost ~]# mkdir -p /usr/local/mysql/{data,tmpdir}
-
更改mysql文件目录及子目录的文件所属和所属组
[root@localhost ~]# chown -R mysql:mysql /usr/local/mysql [root@localhost ~]# ll /usr/local/mysql total 40 drwxr-xr-x. 2 mysql mysql 4096 Jun 19 06:51 bin -rw-r--r--. 1 mysql mysql 17987 Mar 18 2017 COPYING drwxr-xr-x. 2 mysql mysql 6 Jun 19 06:57 data drwxr-xr-x. 2 mysql mysql 52 Jun 19 06:51 docs drwxr-xr-x. 3 mysql mysql 4096 Jun 19 06:51 include drwxr-xr-x. 5 mysql mysql 4096 Jun 19 06:51 lib drwxr-xr-x. 4 mysql mysql 28 Jun 19 06:51 man -rw-r--r--. 1 mysql mysql 2478 Mar 18 2017 README drwxr-xr-x. 28 mysql mysql 4096 Jun 19 06:51 share drwxr-xr-x. 2 mysql mysql 86 Jun 19 06:51 support-files drwxr-xr-x. 2 mysql mysql 6 Jun 19 06:57 tmpdir
-
配置mysql环境变量使用全局变量
[root@localhost ~]# echo "export MYSQL_HOME=/usr/local/mysql" >> /etc/profile [root@localhost ~]# echo "export PATH=\$PATH:\$MYSQL_HOME/bin" >> /etc/profile
-
加载环境变量
[root@localhost ~]# source /etc/profile
-
初始化mysql
[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ 2021-06-18T23:02:08.150243Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-06-18T23:02:08.289275Z 0 [Warning] InnoDB: New log files created, LSN=45790 2021-06-18T23:02:08.322562Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2021-06-18T23:02:08.406438Z 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: 350cdbdd-d089-11eb-bff6-000c295a51a2. 2021-06-18T23:02:08.407076Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2021-06-18T23:02:08.407543Z 1 [Note] A temporary password is generated for root@localhost: vQj)sRbk3oMf
-
编辑/etc/my.cnf配置文件
[root@localhost ~]# vi /etc/my.cnf [mysql] #设置mysql客户端默认字符集 default-character-set=utf8 # 使用自动补齐功能 auto-rehash [mysqld] # 设置3306端口 port=3306 # 设置mysql的安装目录 basedir=/usr/local/mysql # 设置mysql数据库的数据的存放目录 datadir=/usr/local/mysql/data # 临时目录地址 tmpdir=/usr/local/mysql/tmpdir #设置socke文件地址 socket=/tmp/mysql.sock # 允许最大连接数 max_connections=200 # 服务端使用的字符集默认为8比特编码的latin1字符集 character-set-server=utf8 # 创建新表时将使用的默认存储引擎 default-storage-engine=INNODB # 是否对sql语句大小写敏感,默认值0,1表示不敏感 lower_case_table_names=1 max_allowed_packet=16M
-
将mysql服务添加到系统服务列表
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@localhost ~]# chmod +x /etc/init.d/mysqld
-
启动mysql,设置开机自启
[root@localhost ~]# /etc/init.d/mysqld start Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.err'. SUCCESS! [root@localhost ~]# chkconfig --level 35 mysqld on [root@localhost ~]# service mysqld status SUCCESS! MySQL running (9960)
-
修改用户密码添加远程权限
[root@localhost ~]# mysql -uroot -p'vQj)sRbk3oMf' mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.18 Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> set PASSWORD = PASSWORD('password'); Query OK, 0 rows affected, 1 warning (0.00 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> update user set host='%' where user='root'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select host,user from user; +-----------+-----------+ | host | user | +-----------+-----------+ | % | root | | localhost | mysql.sys | +-----------+-----------+ 2 rows in set (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> exit; Bye
-
测试mysql密码
[root@localhost ~]# mysql -uroot -ppassword mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.18 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create database test; Query OK, 1 row affected (0.00 sec)