本人系统为百度云云服务器, 里面基本什么都没有
检查系统是否安装了 mysql
pm -qa | grep mysql 检查mysql 是否安装
rpm -qa | grep mariadb 如果有卸载
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
查看是否存在 mysql 用户和用户组
cat /etc/passwd|grep mysql
cat /etc/group|grep mysql
没有添加mysql 用户组和用户
groupadd mysql
useradd -r -g mysql mysql
在 opt 目录下新建 mysql
mkdir mysql 将下载好的 mysql-tar.gz 上传到 /opt/mysql 目录解压 tar -zxvf mysql-tar.gz
为了看着方便, 修改加压后的mysql文件夹
mv mysql-5.7.28(解压后的文件夹) mysql
在 /opt/mysql/mysql 下新建 data 目录
关联mysql 用户到mysql 用户组
chown -R mysql:mysql /opt/mysql/mysql/
chown -R mysql:mysql /opt/mysql/mysql/data/
chown -R mysql /opt/mysql/mysql/
chown -R mysql /opt/mysql/mysql/data/
更改mysql安装目录的权限
chmod -R 755 /opt/mysql/mysql/
安装 libaio 依赖包
yum install libaio
进入 cd /opt/mysql/mysql/bin 进行初始化
./mysqld --user=mysql --basedir=/opt/mysql/mysql --datadir=/opt/mysql/mysql/data --initialize
完了会生成一个临时密码, (反正我是弄着弄着最后忘记了 - -!)
修改 /opt/mysql/mysql/support-files/mysql.server
因为解压后的mysql 里面 support-files/mysql.server 文件的目录默认是指向 /usr/....下面的, 我们安装的位置为 /opt, 需要修改里面指向的目录
复制 mysql.server TO /etc/init.d/mysqld
cp /opt/mysql/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
修改 my.cnf vim /etc/my.cnf 替换一下内容
[client]
no-beep
socket =/opt/mysql/mysql/mysql.sock
# pipe
# socket=0.0
port=3306
[mysql]
default-character-set=utf8
[mysqld]
basedir=/opt/mysql/mysql
datadir=/opt/mysql/mysql/data
port=3306
pid-file=/opt/mysql/mysql/mysqld.pid
#skip-grant-tables
skip-name-resolve
socket = /opt/mysql/mysql/mysql.sock
character-set-server=utf8
default-storage-engine=INNODB
explicit_defaults_for_timestamp = true
# Server Id.
server-id=1
max_connections=2000
query_cache_size=0
table_open_cache=2000
tmp_table_size=246M
thread_cache_size=300
#限定用于每个数据库线程的栈大小。默认设置足以满足大多数应用
thread_stack = 192k
key_buffer_size=512M
read_buffer_size=4M
read_rnd_buffer_size=32M
innodb_data_home_dir = /opt/mysql/mysql/data
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=16M
innodb_buffer_pool_size=256M
innodb_log_file_size=128M
innodb_thread_concurrency=128
innodb_autoextend_increment=1000
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=300
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
back_log=80
flush_time=0
join_buffer_size=128M
max_allowed_packet=1024M
max_connect_errors=2000
open_files_limit=4161
query_cache_type=0
sort_buffer_size=32M
table_definition_cache=1400
binlog_row_event_max_size=8K
sync_master_info=10000
sync_relay_log=10000
sync_relay_log_info=10000
#批量插入数据缓存大小,可以有效提高插入效率,默认为8M
bulk_insert_buffer_size = 64M
interactive_timeout = 120
wait_timeout = 120
log-bin-trust-function-creators=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
/etc/init.d/mysqld start 启动服务
可能会报错: my_print_defaults: Can't read dir of '/etc/my.cnf.d' ....
报错原因: 不知道是不是说因为在 修改 my.cnf 文件的时候,最后一行 !includedir /etc/my.cnf.d 引起, 反正注释之后就好了
启动服务
sh /opt/mysql/mysql/support-files/mysql.server start
运行 ps -ef|grep mysql 可以看到mysql 的运行信息
因为忘记了临时密码
修改 my.cnf vim /etc/my.cnf 取消注释, 或者添加 skip-grant-tables 免密登陆
重启 mysql 服务
/opt/mysql/mysql/bin/mysql -u root 登陆
执行
flush privileges;
修改 root 密码
alter user 'root'@'localhost' identified by '新密码';
然后注释, 或者删除 skip-grant-tables 这一行 重启 mysql 服务
/opt/mysql/mysql/bin/mysql -u root -p
输入密码.
远程客户端连接报错 "Host '' is not allowed to connect.
在linux 命令行登陆
① use mysql;
② show tables;
③ select host,user from user;
④ update user set host='%' where user='root';
⑤ 重启 mysql
设置mysql开启自启动 centos7.3 mysql5.7.28
将 /opt/mysql/mysql/support-files/mysql.server 复制为 /etc/init.d/mysqld
赋予可执行权限:chmod +x /etc/init.d/mysqld
添加为服务: chkconfig --add mysqld
查看服务列表: chkconfig --list
看到3、4、5状态为开或者为 on 则表示成功。如果是 关或者 off 则执行一下:chkconfig --level 345 mysqld on
查看 mysql 是否为自启动服务
完工!
每天进步一点!