MySQL 8.0 -Linux(龙蜥操作系统)安装mysql

官网下载安装包:https://dev.mysql.com/downloads/mysql/

 

 

安装MYSQL

tar -zxvf mysql-8.0.32-el7-x86_64.tar.gz -C /usr/local/

cd /usr/local/

#重命名操作
------------------重命名mysql部署路径------------------
mv mysql-8.0.32-el7-x86_64 mysql

------------------创建系统mysql组和用户------------------
groupadd mysql

------------------新建mysql用户并加入到mysql组------------------
useradd -r -g mysql mysql

------------------进入到mysql路径下------------------
cd /usr/local/mysql

------------------创建data、log目录------------------
mkdir data
mkdir log

------------------进入到mysql上一级路径下------------------
os.chdir('/usr/local')

------------------当前目录所属者和所属组给mysql------------------
chown -R mysql:mysql mysql

#初始化参数模板
------------------更新my.cnf文件------------------

vi /etc/my.cnf


[mysqld]
port=3306
datadir=/usr/local/mysql/data
log-error=/usr/local/mysql/log/mysql-err.log
pid-file=/usr/local/mysql/data/mysql.pid
user=root
default_authentication_plugin=mysql_native_password
basedir=/usr/local/mysql
lower_case_table_names = 1
sql_mode = STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
innodb_strict_mode=0
#skip-grant-tables
# 禁止MySQL对外部连接进行DNS解析,使用这一选项可以消除MySQL进行DNS解析的时间。但需要注意,如果开启该选项,
# 则所有远程主机连接授权都要使用IP地址方式,否则MySQL将无法正常处理连接请求
#skip-networking
back_log = 600
# MySQL能有的连接数量。当主要MySQL线程在一个很短时间内得到非常多的连接请求/.
max_connections = 1000
max_connect_errors = 6000
# 对于同一主机,如果有超出该参数值个数的中断错误连接,则该主机将被禁止连接。如需对该主机进行解禁,执行:FLUSH HOST。
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 400M
# 该变量之所以取较小默认值是一种预防措施,以捕获客户端和服务器之间的错误信息包,并确保不会因偶然使用大的信息包而导致内存溢出。
binlog_cache_size = 1M
# 一个事务,在没有提交的时候,产生的日志,记录到Cache中;等到事务提交需要提交的时候,则把日志持久化到磁盘
max_heap_table_size = 8M
# 定义了用户可以创建的内存表(memory table)的大小。这个值用来计算内存表的最大行数值。这个变量支持动态改变
tmp_table_size = 16M
#指定单个查询能够使用的缓冲区大小,默认1M
default-storage-engine = InnoDB

#[mysqldump]
#host=localhodst
#user=root
#password=b4%XZCRQp-name-resolve

[client]
socket=/tmp/mysql.sock


------------------安装libaio依赖包------------------
yum install -y libaio

------------------打开mysql目录------------------
cd /usr/local/mysql

------------------安装mysql初始化------------------
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

------------------创建软链接到 /usr/bin------------------
ln -s /usr/local/mysql/bin/mysql /usr/bin

ln -s /usr/local/mysql/bin/mysqldump /usr/bin

------------------添加mysql开机自启动------------------
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

------------------创建mariadb目录------------------
mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql /var/log/mariadb/

------------------打开mysql的bin目录------------------
cd  /usr/local/mysql

------------------启动mysql------------------
./bin/mysqld_safe &


print('------------------获取密码------------------')
password = open('/usr/local/mysql/log/mysql-err.log','r')
for i in password.readlines():
if 'password' in i:
passwd = i.split('localhost: ')[1]
print('初始密码是:'+passwd)
password.close()

---------------------

登录报错如下:
解决办法
1. 查找
没有libncurses.so.5,可能有libncurses.so不同版本的文件,使用命令
find / -name 'libncurses*'
2. 建立软链接
ln -s /usr/lib64/libncurses.so.6.1   /usr/lib64/libncurses.so.5

find / -name 'libtinfo*'

ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5

 


print('------------------修改数据库密码------------------')
print("""mysql --connect-expired-password -uroot -p'"""+passwd.replace('\n','')+"""' -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '"""+new_passwd.replace('\n','')+"'"+'"')
os.popen("""mysql --connect-expired-password -uroot -p'"""+passwd.replace('\n','')+"""' -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '"""+new_passwd.replace('\n','')+"'"+'"')

print('------------------修改允许远程连接------------------')
print("""mysql --connect-expired-password -uroot -p'"""+new_passwd.replace('\n','')+"""' -e "use mysql;update user set host='%' where user = 'root';flush privileges;"""""+'"')
os.popen("""mysql --connect-expired-password -uroot -p'"""+new_passwd.replace('\n','')+"""' -e "use mysql;update user set host='%' where user = 'root';flush privileges;"""""+'"')

print('------------------创建数据库------------------')
print("""mysql --connect-expired-password -uroot -p'"""+new_passwd.replace('\n','')+"""' -e "create database """+database_name.replace('\n','')+""";"""""+'"')
os.popen("""mysql --connect-expired-password -uroot -p'"""+new_passwd.replace('\n','')+"""' -e "create database """+database_name.replace('\n','')+""";"""""+'"')

print('------------------设置log_bin_trust_function_creators=1------------------')
print("""mysql --connect-expired-password -uroot -p'"""+new_passwd.replace('\n','')+"""' -e "use """+database_name.replace('\n','')+""";set global log_bin_trust_function_creators=1;"""""+'"')
os.popen("""mysql --connect-expired-password -uroot -p'"""+new_passwd.replace('\n','')+"""' -e "use """+database_name.replace('\n','')+""";set global log_bin_trust_function_creators=1;"""""+'"')

print('------------------导入sql中------------------')
print("""mysql --connect-expired-password -uroot -p'"""+new_passwd.replace('\n','')+"""' -e "use """+database_name.replace('\n','')+""";source /mnt/csh.sql;"""""+'"')
os.popen("""mysql --connect-expired-password -uroot -p'"""+new_passwd.replace('\n','')+"""' -e "use """+database_name.replace('\n','')+""";source /mnt/csh.sql;"""""+'"')

print('关闭防火墙')
os.popen('systemctl stop firewalld.service')

print('禁止防火墙自启动')
os.popen('systemctl disable firewalld.service')

print('已部署完成')

----------------------------------------------对上述自动部署手动录入命令执行-----------------------------------------------

登录数据库,修改密码,创建数据库,修改远程连接等,创建普通用户并授权...

 

-----------------修改密码------------------------

mysql> alter user 'root'@'localhost' identified by 'GPNU2023gdjssf!';
Query OK, 0 rows affected (0.02 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

-----------------设置远程连接------------------------

mysql> update mysql.user set host = '%' where user = 'root';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 -----------------创建数据库------------------------

mysql> create database gpnu_ltx_sck;
Query OK, 1 row affected (0.02 sec)

mysql> use gpnu_ltx_sck;
Database changed

-----------------设置函数可导入------------------------
mysql> set global log_bin_trust_function_creators=1;
Query OK, 0 rows affected (0.00 sec)

 

-----------------创建普通用户------------------------

mysql> create user 'uufltx'@'%' identified by 'GPnu2023!sck';
Query OK, 0 rows affected (0.02 sec)

-----------------普通用户授权------------------------
mysql> grant all privileges on gpnu_ltx_sck.* to 'uufltx'@'%' with grant option;
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

posted @ 2023-06-19 10:59  小肥猪片儿的小小笔记  阅读(248)  评论(0编辑  收藏  举报