个人笔记,只记录操作
# 修改问题
1、增加 user=mysql 解决 Please read "Security" section of the manual to find out how to run mysqld as root!
2、Access denied for user 'root'@'localhost' (using password: YES)
mysql -p -S /tmp/mysql.sock
密码来自于error.log 中
3、/etc/init.d/mysql start 启动失败
设置/etc/init.d/mysql 中的basedir和datadir目录即可
tar -xJvf mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz
vim /etc/ my.cnf
--my.cnf
[mysqld]
user=mysql
server-id=1
port=3306
mysqlx_port=33060
mysqlx_socket=/tmp/mysqlx.sock
basedir=/opt/mysql
datadir=/opt/mysql/data
socket=/tmp/mysql.sock
pid-file=/tmp/mysqld.pid
log-error=/opt/mysql/log/error.log
slow-query-log=1
slow-query-log-file=/opt/mysql/log/slow.log
long_query_time=0.2
log-bin=/opt/mysql/log/bin.log
relay-log=/opt/mysql/log/relay.log
binlog_format=ROW
relay_log_recovery=1
character-set-client-handshake=FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init_connect ='SET NAMES utf8mb4'
innodb_buffer_pool_size=1G
join_buffer_size=128M
sort_buffer_size=2M
read_rnd_buffer_size=2M
log_timestamps = SYSTEM
lower_case_table_names = 1
default-authentication-plugin=mysql_native_password
groupadd mysql
useradd mysql -g mysql
chown -R mysql:mysql /opt/mysql/
chmod -R 775 /opt/mysql/
ln -s /opt/mysql/bin/mysql /usr/local/bin
ln -s /opt/mysql/bin/mysqld /usr/local/bin
./mysqld --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data --initialize
cp support-files/mysql.server /etc/init.d/mysql
/etc/init.d/mysql start
vim /etc/profile.d/mysql.sh
cat /etc/profile.d/mysql.sh
export PATH=$PATH:/opt/mysql/bin
source /etc/profile.d/mysql.sh
cat error.log | grep -i password
9bSMwd-Ikn+r
./bin/mysql -p -S /tmp/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.12
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>
mysql> alter user root@'localhost' identified by '123456';
Query OK, 0 rows affected (0.12 sec)
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.12 |
+-----------+
1 row in set (0.00 sec)
mysql> show variables like '%valid%pass%';
Empty set (0.01 sec)
增加用户,用于远程访问
mysql> create user root@'%' identified by '123456';
Query OK, 0 rows affected (0.09 sec)
mysql> grant all privileges on *.* to root@'%' with grant option;
Query OK, 0 rows affected (0.15 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.06 sec)
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /opt/mysql/share/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
远程访问mysql,配置操作
/etc/sysconfig/下没有iptables的问题
1、停止并屏蔽firewalld服务
systemctl stop firewalld
systemctl mask firewalld
2、安装iptables-services软件包
yum install iptables-services
3、在引导时启用iptables服务
systemctl enable iptables
4、启动iptables服务
systemctl start iptables
vim /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
systemctl restart iptables.service
centos 7 上配置mysql 开机启动详解
创建配置文件
touch /usr/lib/systemd/system/mysql.service
配置文件
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/opt/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
#Restart=on-failure
#RestartPreventExitStatus=1
#PrivateTmp=false
通过systemctl来启动mysql
systemctl start mysql.service
ps -ef |grep mysql
root 7402 1 0 03:01 pts/1 00:00:00 /bin/sh /opt/mysql/bin/mysqld_safe --datadir=/opt/mysql/data --pid-file=/tmp/mysqld.pid
mysql 7862 7402 0 03:01 pts/1 00:00:05 /opt/mysql/bin/mysqld --basedir=/opt/mysql --datadir=/opt/mysql/data --plugin-dir=/opt/mysql/lib/plugin --user=mysql --log-error=/opt/mysql/log/error.log --pid-file=/tmp/mysqld.pid --socket=/tmp/mysql.sock --port=3306
mysql 8551 1 2 03:15 ? 00:00:00 /opt/mysql/bin/mysqld --defaults-file=/etc/my.cnf
root 8591 4024 0 03:15 pts/1 00:00:00 grep --color=auto mysql
通过systemctl 来设置mysql开机启动
systemctl enable mysql
Created symlink from /etc/systemd/system/multi-user.target.wants/mysql.service to /usr/lib/systemd/system/mysql.service.