您的位置:首页技术文章

linux 安装 mysql 8.0.19 详细步骤及问题解决方法

【字号: 日期:2023-11-01 11:58:28浏览:6作者:馨心

最近买了个腾讯云服务器,搭建环境。

该笔记用于系统上未装过mysql的干净系统第一次安装mysql。自己指定安装目录,指定数据文件目录。

linux系统版本: CentOS 7.3 64位

安装源文件版本:mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz

mysql安装位置:/software/mysql

数据库文件数据位置:/data/mysql

注:未防止混淆,这里都用绝对路径执行命令

除了文件内容中的#,这里所有带#都是linux命令

>mysql 是mysql的命令

步骤:

1、在根目录下创建文件夹software和数据库数据文件/data/mysql

#mkdir /software/#mkdir /data/mysql

2、上传mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz文件到/software下

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

这里我下载的带了router和test的mysql-8.0.19-linux-glibc2.12-x86_64.tar文件,所以多一部解压xz

--------------------#cd /software/#xz -d mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz#tar -xvf mysql-8.0.19-linux-glibc2.12-x86_64.tar

3、更改解压缩后的文件夹名称

#mv /software/mysql-8.0.19-linux-glibc2.12-x86_64/ /software/mysql

4、创建mysql用户组和mysql用户

#groupadd mysql#useradd -r -g mysql mysql

5、关联myql用户到mysql用户组中

#chown -R mysql:mysql /software/mysql/#chown -R mysql:mysql /data/mysql/#chown -R mysql /software/mysql/#chown -R mysql /data/mysql

6、更改mysql安装文件夹mysql/的权限

#chmod -R 755 /software/mysql/

7、安装libaio依赖包,系统自带的有这个依赖包所以不需要安装,不过自带的依赖包会报错

查询是否暗转libaio依赖包

#yum search libaio

如果没安装,可以用下面命令安装

#yum install libaio

8、初始化mysql命令

#cd /software/mysql/bin#./mysqld --user=mysql --basedir=/software/mysql --datadir=/data/mysql --initialize

在执行上面命令时特别要注意一行内容

[Note] A temporary password is generated for root@localhost: o*s#gqh)F4Ck

root@localhost: 后面跟的是mysql数据库登录的临时密码,各人安装生成的临时密码不一样

如果初始化时报错如下:

error while loading shared libraries: libnuma.so.1: cannot open shared objec

是因为libnuma安装的是32位,我们这里需要64位的,执行下面语句就可以解决

#yum install numactl.x86_64

执行完后重新初始化mysql命令

9、启动mysql服务

# sh /software/mysql/support-files/mysql.server start

上面启动mysql服务命令是会报错的,因为没有修改mysql的配置文件,报错内容大致如下:

./support-files/mysql.server: line 239: my_print_defaults: command not found

./support-files/mysql.server: line 259: cd: /usr/local/mysql: No such file or directory

Starting MySQL ERROR! Couldn’t find MySQL server (/usr/local/mysql/bin/mysqld_safe)

10、修改Mysql配置文件

#vim /software/mysql/support-files/mysql.server

修改前

if test -z '$basedir'thenbasedir=/usr/local/mysqlbindir=/usr/local/mysql/binif test -z '$datadir'thendatadir=/usr/local/mysql/datafisbindir=/usr/local/mysql/binlibexecdir=/usr/local/mysql/binelsebindir='$basedir/bin'if test -z '$datadir'thendatadir='$basedir/data'fisbindir='$basedir/sbin'libexecdir='$basedir/libexec'fi

修改后

if test -z '$basedir'thenbasedir=/software/mysqlbindir=/software/mysql/binif test -z '$datadir'thendatadir=/data/mysqlfisbindir=/software/mysql/binlibexecdir=/software/mysql/binelsebindir='$basedir/bin'if test -z '$datadir'thendatadir='$basedir/data'fisbindir='$basedir/sbin'libexecdir='$basedir/libexec'fi

保存退出

#cp /software/mysql/support-files/mysql.server /etc/init.d/mysqld#chmod 755 /etc/init.d/mysqld

11、修改my.cnf文件

#vi /etc/my.cnf

将下面内容复制替换当前的my.cnf文件中的内容

[client]no-beepsocket =/software/mysql/mysql.sock# pipe# socket=0.0port=3306[mysql]#原文的utf8指向UTF8MB3,后续版本要改为UTF8MB4,一步到位吧default-character-set=UTF8MB4[mysqld]basedir=/software/mysqldatadir=/data/mysqlport=3306pid-file=/software/mysql/mysqld.pid#skip-grant-tablesskip-name-resolvesocket = /software/mysql/mysql.sockcharacter-set-server=utf8default-storage-engine=INNODBexplicit_defaults_for_timestamp = true# Server Id.server-id=1max_connections=2000#query_cache_size在8.0版本已经移除,故注释#query_cache_size=0table_open_cache=2000tmp_table_size=246Mthread_cache_size=300#限定用于每个数据库线程的栈大小。默认设置足以满足大多数应用thread_stack = 192kkey_buffer_size=512Mread_buffer_size=4Mread_rnd_buffer_size=32Minnodb_data_home_dir = /data/mysqlinnodb_flush_log_at_trx_commit=0innodb_log_buffer_size=16Minnodb_buffer_pool_size=256Minnodb_log_file_size=128Minnodb_thread_concurrency=128innodb_autoextend_increment=1000innodb_buffer_pool_instances=8innodb_concurrency_tickets=5000innodb_old_blocks_time=1000innodb_open_files=300innodb_stats_on_metadata=0innodb_file_per_table=1innodb_checksum_algorithm=0back_log=80flush_time=0join_buffer_size=128Mmax_allowed_packet=1024Mmax_connect_errors=2000open_files_limit=4161#query_cache_type在8.0版本已经移除,故注释#query_cache_type=0sort_buffer_size=32Mtable_definition_cache=1400binlog_row_event_max_size=8Ksync_master_info=10000sync_relay_log=10000sync_relay_log_info=10000#批量插入数据缓存大小,可以有效提高插入效率,默认为8Mbulk_insert_buffer_size = 64Minteractive_timeout = 120wait_timeout = 120log-bin-trust-function-creators=1sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES## include all files from the config directory#!includedir /etc/my.cnf.d

保存退出

12、启动mysql

#/etc/init.d/mysqld start

新版本的安装包会报错,错误内容如下:

Starting MySQL.Logging to ’/data/mysql/SZY.err’.2018-07-02T10:09:03.779928Z mysqld_safe The file /usr/local/mysql/bin/mysqlddoes not exist or is not executable. Please cd to the mysql installationdirectory and restart this script from there as follows:./bin/mysqld_safe&See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more informationERROR! The server quit without updating PID file (/software/mysql/mysqld.pid).

因为新版本的mysql安全启动安装包只认/usr/local/mysql这个路径。

解决办法:

方法1、建立软连接

#cd /usr/local/mysql#ln -s /sofware/mysql/bin/myslqd mysqld

方法2、修改mysqld_safe文件(有强迫症的同学建议这种,我用的这种)

# vim /software/mysql/bin/mysqld_safe

将所有的/usr/local/mysql改为/software/mysql

保存退出。(可以将这个文件拷出来再修改然后替换)

13、登录mysql

这里我登陆不了,被denny了,类似这样的错误:

ERROR 1045 (28000): Access denied for user ’root’@’localhost’ (using password: NO)。

参考https://cloud.tencent.com/developer/article/1188636

改为这个操作:

1.停止mysql数据库

/etc/init.d/mysqld stop

(或者直接 kill -9 [PID] 杀进程!)

2.执行如下命令

mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

3.使用root登录mysql数据库

mysql -u root mysql

4.更新root密码

最新版MySQL请采用如下SQL:

mysql> ALTER USER ’root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ’newpassword’;

5.刷新权限

mysql> FLUSH PRIVILEGES;

6.退出mysql

mysql> quit

7.重启mysql

/etc/init.d/mysqld restart

8.使用root用户重新登录mysql

mysql -uroot -p Enter password: <输入新设的密码newpassword>---------------------------------------------------------------------------------------------------------------------------#/software/mysql/bin/mysql -u root ?p

14、输入临时密码。临时密码就是第8条root@localhost:后面的内容

15、修改mysql的登录密码

>mysql set password=password(’root’);>mysql grant all privileges on *.* to root@’%’ identified by ’root’;>mysql flush privileges;

16、完成,此时mysql的登录名root 登录密码root

总结

到此这篇关于linux 安装 mysql 8.0.19 详细步骤及问题解决方法的文章就介绍到这了,更多相关linux安装mysql8.0.19 内容请搜索优爱好网以前的文章或继续浏览下面的相关文章希望大家以后多多支持优爱好网!

标签: Linux系统
相关文章: