操作环境:
CentOS Linux release 7.2.1511 (Core)
用户:/home/gll
安装包:
mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
操作过程:
tar xvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C ~/
cd ~
mv mysql-5.7.19-linux-glibc2.12-x86_64/ mysql-5.7.19
cd mysql-5.7.19/
mkdir data logs tmp
vim my.cnf
配置环境变量:
vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
MYSQL_HOME=$HOME/mysql-5.7.19
PATH=$MYSQL_HOME/bin:$PATH
export MYSQL_HOME
使其生效:
source .bash_profile
echo $MYSQL_HOME
/home/gll/mysql-5.7.19
my.cnf配置:
[client]
port=3306
socket=[client]
port=3306
socket=/home/gll/mysql-5.7.19/tmp/mysql.sock
[mysqld]
port=3306
basedir=/home/gll/mysql-5.7.19/
datadir=/home/gll/mysql-5.7.19/data
pid-file=/home/gll/mysql-5.7.19/data/localhost.pid
general-log-file=/home/gll/mysql-5.7.19/data/localhost.log
slow-query-log-file=/home/gll/mysql-5.7.19/data/localhost-slow.log
character-sets-dir=/home/gll/mysql-5.7.19/share/charsets/
language=/home/gll/mysql-5.7.19/share/
lc-messages-dir=/home/gll/mysql-5.7.19/share/
plugin-dir=/home/gll/mysql-5.7.19/plugin/
slave-load-tmpdir=/home/gll/mysql-5.7.19/tmp
socket=/home/gll/mysql-5.7.19/tmp/mysql.sock
tmpdir=/home/gll/mysql-5.7.19/tmp/
各项属性解释:
属性 | 默认参数 | 作用 |
---|---|---|
basedir | /usr/local/mysql/ | Path to installation directory. All paths are usually resolved relative to this |
datadir | /usr/local/mysql/data/ | Path to the database root directory |
general-log-file | /usr/local/mysql/data/localhost.log | Log connections and queries to given file |
pid-file | /usr/local/mysql/data/localhost.pid | Pid file used by safe_mysqld |
slow-query-log-file | /usr/local/mysql/data/localhost-slow.log | Log slow queries to given log file. Defaults logging to hostname-slow.log. Must be enabled to activate other slow log options |
character-sets-dir | /usr/local/mysql/share/charsets/ | Directory where character sets are |
language | /usr/local/mysql/share/ | Client error messages in given language. May be given as a full path. Deprecated. Use --lc-messages-dir instead. |
lc-messages-dir | /usr/local/mysql/share/ | Directory where error messages are |
plugin-dir | /usr/local/mysql/lib/plugin/ | Directory for plugins |
slave-load-tmpdir | /tmp | The location where the slave should put its temporary files when replicating a LOAD DATA INFILE command |
socket | /tmp/mysql.sock | Socket file to use for connection |
tmpdir | /tmp | Path for temporary files. Several paths may be specified, separated by a colon, in this case they are used in a round-robin fashion |
初始化:
/home/gll/mysql-5.7.19/bin/mysqld --defaults-file=/home/gll/mysql-5.7.19/my.cnf --initialize --user=gll --datadir=/home/gll/mysql-5.7.19/data --basedir=/home/gll/mysql-5.7.19
运行结果:
[Warning] Changed limits: max_open_files: 1024 (requested 5000)
[Warning] Changed limits: table_open_cache: 431 (requested 2000)
[Warning] The syntax '--language/-l' is deprecated and will be removed in a future release. Please use '--lc-messages-dir
[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server optionetails).
[Warning] InnoDB: New log files created, LSN=45790
[Warning] InnoDB: Creating foreign key constraint system tables.
[Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Ge78ea-11ea-a135-54e1ade3798b.
[Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
[Note] A temporary password is generated for root@localhost: z_9XCZf!ar&*
将最后一行的密码记下来,后面需要用到
修改mysql.server文件
vim /home/gll/mysql-5.7.19/support-files/mysql.server
basedir=/home/gll/mysql-5.7.19/
datadir=/home/gll/mysql-5.7.19/data
开启mysql
cd /home/gll/mysql-5.7.19/support-files/
./mysql.server start
Starting MySQL. SUCCESS!
使用刚刚记住的临时密码登陆mysql,修改密码为123456,配置远程登陆
[gll@localhost ~]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.19
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>
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all PRIVILEGES on *.* to root@'%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit;
Bye
至此使用非root安装已经完成
如果有root用户权限可以做以下操作:
将程序拷贝至/etc/init.d/目录下,以便于使用service命令启动mysql
[gll@localhost ~]$ su -
Password:
Last login: Tue Apr 7 11:14:53 EDT 2020 from 192.168.1.100 on pts/1
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# cp /home/gll/mysql-5.7.19/support-files/mysql.server /etc/init.d/mysql
[root@localhost ~]# chmod 755 /etc/init.d/mysql
设置开机自启,mysql的3、4、5是on则表示成功
[root@localhost ~]# chkconfig --add mysql
[root@localhost ~]# chkconfig mysql on
[root@localhost ~]# chkconfig --list
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]'.
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off