linuxmysql8安装

在Linux系统中安装MySQL 8,首先需要确保系统已经安装了必要的依赖库,以下是在基于Debian的系统(如Ubuntu)和基于RHEL的系统(如CentOS)中安装MySQL 8的步骤:

创新互联公司专注于企业网络营销推广、网站重做改版、安多网站定制设计、自适应品牌网站建设、H5页面制作商城网站建设、集团公司官网建设、外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为安多等各大城市提供网站开发制作服务。

1. 更新系统并安装依赖库**

对于基于Debian的系统:

sudo apt update
sudo apt upgrade
sudo apt install libaio1
sudo apt install cmake

对于基于RHEL的系统:

sudo yum update
sudo yum install epel-release
sudo yum install libaio
sudo yum install cmake

2. 下载MySQL 8源码**

访问MySQL官方网站()下载最新的MySQL 8源码包,选择适合你的系统的版本,然后复制下载链接。

以CentOS为例,使用wget命令下载:

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.26.tar.gz

3. 解压源码包**

tar -zxvf mysql-8.0.26.tar.gz

4. 编译并安装MySQL 8**

进入解压后的目录:

cd mysql-8.0.26

创建一个用于存放编译结果的目录:

mkdir build && cd build

使用CMake配置编译选项:

cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DWITH_BOOST=boost -DWITH_SYSTEMD=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=OFF -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_SSL=system -DWITH_ZLIB=bundled -DWITH_LIBWRAP=0 -DDEFAULT_AUTH_PLUGIN=mysql_native_password -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=OFF -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_SSL=system -DWITH_ZLIB=bundled -DWITH_LIBWRAP=0 -DDEFAULT_AUTH_PLUGIN=mysql_native_password

编译并安装MySQL:

make && sudo make install

5. 将MySQL添加到环境变量**

编辑`~/.bashrc`文件,添加以下内容:

export MYSQL_ROOTDIR=/usr/local/mysql/bin
export MYSQL_HOME=$MYSQL_ROOTDIR/mysql-8.0.26-linux-glibc2.12-x86_64
export PATH=$MYSQL_HOME:$PATH

保存文件后,执行以下命令使更改生效:

source ~/.bashrc

6. 初始化数据库**

“`bash

sudo mysqld –initialize –user=mysql –basedir=$MYSQL_HOME –datadir=$MYSQL_DATADIR –tmpdir=$MYSQLTMPDIR –console –skip-grant-tables &> init.out & echo “Waiting for confirmation of MySQL server startup” && sleep 60 && echo “MySQL Server started successfully” && ps | grep mysqld &> psout && killall mysqld &> killout && echo “MySQL Server stopped” && exit $? & wait $! && echo “MySQL Server exited with error code $?” && cat init.out > errors.log && cat psout > out.log && cat killout > killout.txt && exit $? || (cat errors.log >&2; exit $?) || (cat out.log >&2; exit $?) || (cat killout.txt >&2; exit $?) # If an error occurred, the first command will not complete so we need to use wait $! here instead of the last command which will not execute if an error occurred in the previous step of the script and will cause the script to exit immediately with a non zero status code without waiting for MySQL to start or report any errors that may have occurred during its startup process. The second command will redirect all output from the commands above to their respective log files and the third command will redirect any output remaining on the standard output stream to a file called killout.txt so that it can be viewed later using the `grep` command or by other means as needed. Finally, the exit status of the last command is returned to the caller of this script so that they can determine whether or not the MySQL server was able to start successfully or if there were any errors encountered during its startup process. If an error occurred, the exit status will be non zero otherwise it will be zero indicating success. If you prefer to return a different value to indicate success or failure, you can modify this script accordingly by changing the number at the end of the last line to something else like `exit $? &>&1`. You can also add additional error checking and logging as needed depending on your requirements for this script. ### Related Questions & Answers ### How do I check if MySQL is running on my system? You can use the following command to check if MySQL is running on your system: `ps | grep mysqld`. If the output includes a line that starts with `mysqld`, then MySQL is running on your system. ### How do I connect to a MySQL database using Python? You can use the `pymysql` library in Python to connect to a MySQL database as follows: `import pymysql conn = pymysql.connect(host=’localhost‘, user=’root’, password=’yourpassword’, db=’yourdatabase’) cursor = conn.cursor() cursor.execute(“SELECT * FROM yourtable”) results = cursor.fetchall() for row in results: print(row) conn.close()` Replace `localhost`, `root`, `yourpassword`, `yourdatabase`, and `yourtable` with your actual values for these parameters. ### How do I create a new user in MySQL? To create a new user in MySQL, you can use the following command: `CREATE USER ‘newuser’@’localhost’IDENTIFIED BY ‘password’;`. Replace `newuser`, `localhost`, and `password` with your desired values for these parameters. ### How do I grant privileges to a user in MySQL? To grant privileges to a user in MySQL, you can use the following command: `GRANT ALL PRIVILEGES ON databasename.* TO ‘username’@’localhost’;`. Replace `databasename`, `username`, and `localhost` with your desired values for these parameters. ### How do I delete a user in MySQL? To delete a user in MySQL, you can use the following command: `DROP USER ‘username’@’localhost’;`. Replace `username` and `localhost` with your desired values for these parameters

网站标题:linuxmysql8安装
文章位置:http://www.mswzjz.com/qtweb/news14/169964.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联