# 编译安装mysql程序(1线程近1个小时) [root@bogon mysql-5.7.21]# make -j `grep processor /proc/cpuinfo | wc -l` [root@bogon mysql-5.7.21]# make install
# mysql安装成功 /usr/local/mysql下的文件,此时data中是空的,还没有安装数据库实例 [root@bogon mysql]# ll total 64 drwxr-xr-x. 2 mysql mysql 4096 Jan 2000:07 bin -rw-r--r--. 1 mysql mysql 17987 Dec 2722:46 COPYING -rw-r--r--. 1 mysql mysql 17987 Dec 2722:46 COPYING-test drwxr-xr-x. 5 mysql mysql 178 Jan 2002:01 data drwxr-xr-x. 2 mysql mysql 55 Jan 2000:06 docs drwxr-xr-x. 3 mysql mysql 4096 Jan 2000:06 include drwxr-xr-x. 4 mysql mysql 191 Jan 2000:07 lib drwxr-xr-x. 4 mysql mysql 30 Jan 2000:06 man drwxr-xr-x. 10 mysql mysql 4096 Jan 2000:08 mysql-test -rw-r--r--. 1 mysql mysql 2478 Dec 2722:46 README -rw-r--r--. 1 mysql mysql 2478 Dec 2722:46 README-test drwxr-xr-x. 28 mysql mysql 4096 Jan 2000:08 share drwxr-xr-x. 2 mysql mysql 90 Jan 2000:08 support-files
# 与此同时,在/etc/文件夹下生成mysql的配置文件 [root@bogon mysql]# ll /etc/ -rw-r--r--. 1 root root 739 Jan 2001:30 my.cnf # mysqld 配置文件 drwxr-xr-x. 2 root root 31 Jan 2002:42 my.cnf.d # mysql client端文件配置
log_error = /var/log/mysql/error.log # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd
# # include all files from the config directory # !includedir /etc/my.cnf.d --------------------my.cnf---------------------------------
# 配置 /etc/my.cnf.d/mysql-clients.cnf ------------------------mysql-clients.cnf start----------------------------------------- [root@bogon bin]# vi /etc/my.cnf.d/mysql-clients.cnf # # These groups are read by MariaDB command-line tools # Use it for options that affect only one utility # # 在配置文件中添加“[client]”选项和“[mysql]”选项 # 并使用这两个选项下的“socket”参数值,与“[mysqld]”选项下的“socket”参数值,指向的socket文件路径完全一致
# 解决问题: connect to local MySQL server through socket /var/lib/mysql/mysql.sock
# mysql加入系统服务 [root@bogon bin]# cd /usr/local/mysql/support-files/ [root@bogon support-files]# cp mysql.server /etc/init.d/mysql [root@bogon support-files]# chkconfig --add mysql # mysql加入系统服务 [root@bogon support-files]# chkconf ig mysql on # 开机启动 [root@bogon support-files]# service mysql start
# 查看mysql监听端口 [root@bogon support-files]# lsof -i:3306 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mysqld 8826 mysql 32u IPv6 538910t0 TCP *:mysql (LISTEN)
# mysql进程 [root@bogon support-files]# ps -ef|grep mysql
# mysql status [root@bogon support-files]# service mysql status Redirecting to /bin/systemctl status mysql.service ● mysqld.service - LSB: start and stop MySQL Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled) Active: inactive (dead) since Sat 2018-01-2002:01:27 EST; 1h 26min ago Docs: man:systemd-sysv-generator(8) Process: 8591 ExecStop=/etc/rc.d/init.d/mysqld stop (code=exited, status=0/SUCCESS)
Jan 2000:49:06 bogon systemd[1]: Starting LSB: start and stop MySQL... Jan 2000:49:06 bogon mysqld[1925]: Starting MySQL SUCCESS! Jan 2000:49:06 bogon systemd[1]: Started LSB: start and stop MySQL. Jan 2002:01:27 bogon systemd[1]: Stopping LSB: start and stop MySQL... Jan 2002:01:27 bogon mysqld[8591]: ERROR! MySQL server PID file could not be found! Jan 2002:01:27 bogon systemd[1]: Stopped LSB: start and stop MySQL.
# 尝试登陆mysql [root@bogon support-files]# mysql -u root -p Enter password: **Access denied for user 'root'@'localhost' (using password: NO)**
# 解决问题Access denied for user 'root'@'localhost.... [root@bogon support-files]# /etc/init.d/mysql stop [root@bogon support-files]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking & [root@bogon support-files]# mysql -u root mysql #使用mysql数据库 mysql> update user set authentication_string=PASSWORD("123456")where user="root"; # 已经没有password这个字段了.. mysql> flush privileges; #更新权限 mysql> quit #退出
# 尝试再次登陆 [root@bogon etc]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.21
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> show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql> alter user 'root'@'localhost' identified by '111111'; Query OK, 0 rows affected (0.00 sec)