*注:本文安装的是mysql5.6的版本,反复安装三遍总结下来的详细安装步骤。
1. Unzip the MySQL compressed package to the current directory
tar -xvzf mysql-5.6.45-linux-glibc2.12-x86_64.tar.gz
2. Move the installation package to the specified directory and modify the file name to'mysql'
mv mysql-5.6.45-linux-glibc2.12-x86_64 /usr/local/mysql
3. Create a data warehouse directory
mkdir /data/mysql
4. Add mysql user and mysql user group
The mysql user and user group added here are later used to assign permissions to the MySQL installation directory, so there is no need to set a password, because this user cannot directly log in to the Linux system.
4.1 Add mysql user group
groupadd mysql
4.2. Add a mysql user, and specify that the initial group of the mysql user is the mysql group
useradd -g mysql mysql
5. Enter the MySQL installation directory
cd /usr/local/mysql/
6. Modify the current directory owner as the mysql user
chown -R mysql .
chgrp -R mysql .
修改data/mysql目录权限为MySQL用户
chown -R mysql /data/mysql
7. Initialize the database: execute the command
./scripts/mysql_install_db --user=mysql
7.1 Initialization error (please ignore if no error is reported): The solution is to install the autoconf library
执行命令:yum -y install autoconf
Then execute the command to initialize the database again.
8. Modify the current directory permissions to root user
chown -R root:root ./
At this point, the installation is complete.
10. Configuration parameters
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
11. Modify the system configuration file
11.1 Enter the configuration directory
cd /usr/local/mysql/support-files/
11.2 Copy and modify the file name to the specified directory
1)把mysql配置文件放到指定目录
cp my-default.cnf /etc/my.cnf
如果不存在my-default.cnf文件或不清楚my.cnf的配置,可以参考博主的my.cnf文件配置,在本博客底部。
2)启动脚本放到开机初始化目录
cp mysql.server /etc/init.d/mysql
11.3 Edit mysql file
vim /etc/init.d/mysql
添加如下配置:
basedir=/usr/local/mysql
datadir=/data/mysql
12. Start the mysql service
service mysql start
13. View the current status of mysql
ps -ef|grep mysql
14. Modify the root user password of mysql (the initial root password is empty)
./bin/mysqladmin -u root password '密码'
修改报错(不报错的可以略过):找不到mysql.sock文件
处理: 1.使用kill命令杀掉mysql的进程
2.然后重新启动mysql服务
3.再次查看/tmp目录,
此时已经生成mysql.sock文件,问题解决
15.Log in to mysql
mysql -hlocalhost -uroot -p
16. Set the host address of the root account
**a)使用%代替IP地址,代表所有ip都可以远程连接**
mysql> grant all privileges on *.* to root@'%' identified by 'root';
**b)刷新,使配置生效**
mysql>flush privileges;
17. View the mysql table, the configuration takes effect
mysql> use mysql;
mysql> select host,user from user;
退出mysql命令窗口
mysql> exit
At this point, you can use client tools such as Navicat to connect to the mysql database. If it is an Alibaba Cloud server, you need to create a new port 3306.
18.Add system path
a) Edit the profile file
vim /etc/profile
添加配置export PATH=/usr/local/mysql/bin:$PATH
b) Refresh to make the modification of the profile file effective
source /etc/profile
19. Configure mysql to start automatically at boot
chmod 755 /etc/init.d/mysql
chkconfig --add mysql
chkconfig --level 345 mysql on
At this point, the installation and configuration of mysql is officially completed.
-View mysql status
#service mysql status
-stop mysql
#service mysql stop
-start mysql
#service mysql start
Find mysql users and user groups
more /etc/passwd | grep mysql
more /etc/shadow | grep mysql
delete users
userdel mysql
my.cnf configuration information:
#For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
log_bin
character-set-server=utf8
collation-server=utf8_bin
init-connect='SET NAMES utf8'
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
bind-address = 0.0.0.0
server_id = 22206
socket = /data/mysql/mysql.sock
binlog_format = statement
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
log_bin_trust_function_creators = on
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES