目录
1、检查库文件是否存在
2、创建mysql用户组、mysql用户
3、解压安装
4、进入mysql目录
5、创建mysql数据存储目录
6、创建mysql配置文件my.cnf
7、初始化数据库
8、设置开机启动
9、启动mysql
10、登录mysql修改root默认命令
11、配置mysql环境变量
12、创建远程登录账号
13、建库建表
如有删除 (rpm -e --nodeps )
rpm -qa | grep mysql
rpm -qa |grep mariadb
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
进入到mysql压缩包目录,解压mysql到/usr/local目录下,并重命名为mysql
tar -zxf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local
mv /usr/local/mysql-5.7.37-linux-glibc2.12-x86_64 /usr/local/mysql
cd /usr/local/mysql
mkdir -p /data/mysql
[mysqld]
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
character_set_server=utf8mb4
slow_query_log = ON
slow_query_log_file = /data/mysql/slow-query.log
long_query_time = 1
server-id = 1
binlog-format=ROW
log-bin=mysql-bin
skip-external-locking
skip-name-resolve
innodb_buffer_pool_size = 2G
innodb_flush_log_at_trx_commit = 2
#innodb_log_file_size = 256M
innodb_file_per_table = 1
key_buffer_size = 16K
max_allowed_packet = 256M
tmp_table_size = 800M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
net_buffer_length = 2K
thread_stack = 128K
myisam_sort_buffer_size = 64M
thread_cache_size = 128
#query_cache_size = 32M
max_connections=500
wait_timeout = 300
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 100M
sort_buffer_size = 200M
[mysqlhotcopy]
interactive-timeout
./bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql
安装成功后显示root密码(或者在datadir目录下的xx.err文件中查看)
拷贝启动文件到/etc/init.d/下并重命令为mysqld
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
修改启动文件设置basedir和datadir
vi /etc/init.d/mysqld
设置开机启动(可不配置)
systemctl enable mysqld
/etc/init.d/mysqld start
./bin/mysql -u root -p
5.7版本
set password for root@localhost = password('wsx-123');
8.0版本
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'wsx-123';
FLUSH PRIVILEGES;刷新权限表,使密码生效
在/etc/profile.d目录下新增 mysql.sh文件,配置mysql环境(export PATH=/usr/local/mysql/bin:$PATH),执行 source /etc/profile.d/mysql.sh 使之生效。
创建用户
create user root@'%' identified with mysql_native_password by 'wsx-123';
授权
GRANT ALL ON *.* TO 'root'@'%';
刷新权限
FLUSH PRIVILEGES;
创建数据库
create database test_db default character set utf8mb4 collate utf8mb4_unicode_ci;
创建表
CREATE TABLE `table_test` (
`id` int NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主表id',
`name` varchar(255) NOT NULL COMMENT '名称'
) ;