千家信息网

搭建mysql数据库

发表于:2024-11-20 作者:千家信息网编辑
千家信息网最后更新 2024年11月20日,#安装编译工具与插件yum -y install \gcc \gcc-c++ \make \ncurses \ncurses-devel \bison \cmake#建立数据库程序用户useradd
千家信息网最后更新 2024年11月20日搭建mysql数据库
#安装编译工具与插件yum -y install \gcc \gcc-c++ \make \ncurses \ncurses-devel \bison \cmake
#建立数据库程序用户useradd -s /sbin/nologin  mysql
yum install lrz* -y

#解压mysql安装包tar xf mysql-boost-5.7.20.tar.gz -C /opt/
cd /opt/mysql-5.7.20/cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \-DSYSCONFDIR=/etc \-DSYSTEMD_PID_DIR=/usr/local/mysql \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_ARCHIVE_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \-DMYSQL_DATADIR=/usr/local/mysql/data \-DWITH_BOOST=boost \-DWITH_SYSTEMD=1
#编译与安装make && make install
#对数据库目录进行权限配置chown -R mysql.mysql /usr/local/mysql/
vi /etc/my.cnf删除里面所有内容并把以下内容添加到里面[client]port = 3306 default-character-set=utf8socket = /usr/local/mysql/mysql.sock[mysql]port = 3306default-character-set=utf8socket = /usr/local/mysql/mysql.sock[mysqld]user = mysqlbasedir = /usr/local/mysqldatadir = /usr/local/mysql/dataport = 3306character_set_server=utf8pid-file = /usr/local/mysql/mysqld.pidsocket = /usr/local/mysql/mysql.sockserver-id = 1sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES  :wq      //保存退出
chown mysql:mysql /etc/my.cnf       //配置文件属主与属组
#设置环境变量echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile          //把这两个路径添加到环境变量中,并放到profile文件中使之开机自运行,否则不生效echo 'export PATH' >> /etc/profile                   //设为全局变量,使它使用环境更广source /etc/profile               //立即生效
#初始化数据库cdcd /usr/local/mysql/bin/mysqld \--initialize-insecure \--user=mysql \--basedir=/usr/local/mysql \--datadir=/usr/local/mysql/data
cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload       systemctl start mysqldnetstat -anpt | grep 3306    //查看服务运行状态

systemctl enable mysqld     //设为开机启动
#访问数据库操作mysqladmin -u root -p password "abc123"    //给root账号设置密码mysql -uroot  -pabc123      //登录数据库   有密码的加"-p",如果没有密码不用加"-p"数据库安装配置成功,退出则输入"quit"

0