mysql安装初始化

1.安装

yum install -y libaio-devel

cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld

echo 'export PATH=//datamysql/bin:$PATH' >>/etc/profile

source /etc/profile

2.初始化

mysqld --defaults-file=/etc/my.cnf --initialize

mysqld --initialize-insecure --user=mysql --basedir=/var/lib/mysql --datadir=/var/lib/mysql/data

mysqld --user=mysql --basedir=/var/lib/mysql --datadir=/var/lib/mysql/data

3.生成service

cat > /lib/systemd/system/mysqld.service <<EOF
[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=/var/lib/mysql/bin/mysqld

LimitNOFILE = 5000

EOF

4.配置文件

cat >/etc/my.cnf <<EOF

[mysqld]

user=mysql

basedir=/var/lib/mysql

datadir=/var/lib/mysql/data

socket=/tmp/mysql.sock

[mysql]

socket=/tmp/mysql.sock

prompt=mysql5091_db01 [\\d]>

[client]

socket=/tmp/mysql.sock

EOF

5. 配置权限修改root密码

跳过权限验证(可选)
– 1.修改vim /etc/my.cnf增加skip-grant-tables(修改后记得注掉,重启mysql)
– 2.mysqld_safe –user=mysql –skip-grant-tables –skip-networking &
– 3.mysqld –user=mysql –skip-grant-tables –skip-networking &

mysql -uroot -p

-- 方式1
update user SET Password=PASSWORD('root@123') where USER='root';
FLUSH PRIVILEGES;

-- 方式2
update user SET authentication_string=PASSWORD('root@123') where USER='root';
FLUSH PRIVILEGES;

-- 方式3(8.0版本)
alter user 'root'@'localhost' IDENTIFIED BY 'Root@123';
FLUSH PRIVILEGES;

alter user 'root'@'%' IDENTIFIED BY 'Root@123';
FLUSH PRIVILEGES;

-- 方式4
use mysql;
set password='Root@123';
FLUSH PRIVILEGES;

7.创建用户

create database 'ideal' DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

create user '#userName'@'#host' identified by '#passWord';

create user 'root'@'%' identified by 'Root@123';

CREATE USER 'root'@'%' IDENTIFIED WITH 'mysql_native_password' BY 'Root@123';

FLUSH PRIVILEGES;

8.授权

root账户中的host项是localhost表示该账号只能进行本地登录,我们需要修改权限

-- 方式1
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Root@123' WITH GRANT OPTION;
FLUSH PRIVILEGES;


-- 方式2(8.0版本)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;

-- 方式3(8.0版本)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;

-- 方式4(8.0版本)
use mysql;
select user,authentication_string,host from user;
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;

留下评论