借鉴博客:https://blog.youkuaiyun.com/zhou920786312/article/details/77750604
1、下载mysql:https://dev.mysql.com/downloads/mysql/
2、解压文件,root用户
tar -xzvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
3、移动文件
[root@promote local]# mkdir mysql
[root@promote local]# mv mysql-5.7.24-linux-glibc2.12-x86_64/* mysql
4、创建用户和用户组
[root@promote local]# groupadd mysql
[root@promote local]# useradd -r -g mysql mysql
5、创建data文件夹,修改文件夹权限
[root@promote local]# cd mysql/
[root@promote mysql]# mkdir data
[root@promote mysql]# cd ..
[root@promote local]# chown -R mysql mysql/
[root@promote local]# chgrp -R mysql mysql/
6、检查是否有以前版本
rpm -qa | grep mysql
有的话删除:
rm -e –-nodeps mysql-libs-5.1.52.x86_64
7、安装
[root@promote mysql]# cd bin/
[root@promote bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/--datadir=/usr/local/mysql/data/
2018-11-08T12:37:03.577046Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-08T12:37:03.577221Z 0 [ERROR] Can't find error-message file '/usr/local/mysql/--datadir=/usr/local/mysql/data/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2018-11-08T12:37:04.922103Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-11-08T12:37:05.186604Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-11-08T12:37:05.308183Z 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: ffca7458-e352-11e8-9143-7824af84e0f8.
2018-11-08T12:37:05.330894Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-11-08T12:37:05.331838Z 1 [Note] A temporary password is generated for root@localhost: np_>Uj:Lq7dr
[root@promote bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US
2018-11-08T12:37:46.213281Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-08T12:37:47.578129Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-11-08T12:37:47.827161Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-11-08T12:37:47.949198Z 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: 1934f4f2-e353-11e8-9203-7824af84e0f8.
2018-11-08T12:37:47.969999Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-11-08T12:37:47.970653Z 1 [Note] A temporary password is generated for root@localhost: q;SRP.hUe8em
其中q;SRP.hUe8em为安装后的密码.
8、启动
修改配置文件:vi /etc/my.cnf
添加内容:
[mysql]
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/
启动数据库:
[root@promote etc]# cd /usr/local/mysql/bin/
[root@promote bin]# ./mysqld_safe --user=mysql &
[1] 10617
[root@promote bin]# 2018-11-08T12:50:41.854846Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
[1]+ 退出 1 ./mysqld_safe --user=mysql
此错误要去创建文件夹,并赋予mysql用户权限
[root@promote bin]# mkdir /var/log/mariadb
[root@promote bin]# cat>>/var/log/mariadb/mariadb.log
^C
[root@promote bin]# chown -R mysql:mysql /var/log/mariadb
[root@promote bin]# ./mysqld_safe --user=mysql &
[1] 11276
[root@promote bin]# 2018-11-08T13:02:35.138810Z mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
2018-11-08T13:02:35.221937Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
2018-11-08T13:02:35.836091Z mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended
[1]+ 完成 ./mysqld_safe --user=mysql
9、设置自启动
[root@promote bin]# cd ..
[root@promote mysql]# cd support-files/
[root@promote support-files]# cp mysql.server /etc/init.d/mysql
[root@promote support-files]# chmod +x /etc/init.d/mysql
[root@promote support-files]# chkconfig --add mysql
[root@promote support-files]# chkconfig --list mysql
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。
要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'。
mysql 0:关 1:关 2:开 3:开 4:开 5:开 6:关
10、登录数据库
[root@promote support-files]# service mysql start
Starting MySQL. SUCCESS!
[root@promote support-files]# cd ..
[root@promote mysql]# cd bin/
[root@promote bin]# ./mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
有错误
[root@promote bin]# rm -rf /var/lib/mysql/*
[root@promote bin]# killall mysqld
[root@promote bin]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Failed to start mysqld.service: Unit not found.
[root@promote bin]# /etc/rc.d/init.d/mysqld status
-bash: /etc/rc.d/init.d/mysqld: 没有那个文件或目录
[root@promote bin]# service mysql stop
ERROR! MySQL server PID file could not be found!
[root@promote bin]# service mysql start
Starting MySQL..... ERROR! The server quit without updating PID file (/var/lib/mysql/promote.cache-dns.local.pid).
[root@promote bin]# cp /etc/my.cnf my.cnf.bak
[root@promote bin]# rm /etc/my.cnf
rm:是否删除普通文件 "/etc/my.cnf"?y
[root@promote bin]# /etc/init.d/mysql start
Starting MySQL.Logging to '/usr/local/mysql/data/promote.cache-dns.local.err'.
SUCCESS!
[root@promote bin]# service mysql start
Starting MySQL SUCCESS!
[root@promote bin]# 2018-11-08T13:22:17.560078Z mysqld_safe A mysqld process already exists
[root@promote bin]# ./mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24
Copyright (c) 2000, 2018, 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("root");
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>