免安装tar包MySQL的配置
同时一个版本分有不同的分发形式,有的以 rpm 包,有的以 tar 包,而有的以源代码的方式发布。rpm包安装方便,但是不够灵活;源代
这两天安装MYSQL遇到很多问题,找了很多材料,把总结的东西写出来看看
1、首先选择合适的 mysql 版本。 去
下最新的版本 mysql
同时一个版本分有不同的分发形式,有的以 rpm 包,有的以 tar 包,而有的以源代码的方式发布。rpm包安装方便,但是不够灵活;源代码很灵活却需要编译,所以我下载了 tar 包来安装,因为它做了优化编译。 一般tar包直接解压就可以使用了,但是想启动和停止方便还需要修改一些链接这里就都写出来咯!
2、安装mysql。
rpm包的安装不在赘述,源代码和tar包最好安装在 /usr/local/mysql 中,,其方法是源代码 configure 时候加入 ――prefix=/usr/loal/mysql,而 tar 包直接解压到 /usr/local/mysql 即可。
3、安装后配置。
在 mysql 的目录里(安装后)找到 /bin/mysql_install_db 并运行,tar 包在 mysql 中的 脚本s 目录下,这样数据库就安装了:
$ cd /usr/local/mysql
$ ./bin/mysql_install_db (初始化数据库)
添加组 mysql 和用户 mysql,把其初始目录设置到 mysql 的安装目录里,并将 mysql 设置成 mysql 文件夹的所有者,这样可以防止不能连接 MySql 服务器错误:
$ useradd -M -o -r -d /usr/local/mysql -s /bin/bash -c "mysql user" -u 27 mysql
$ cd /usr/local/
$ chmod 750 mysql -R
$ chgrp mysql mysql -R
$ chown mysql mysql -R
执行 mysql 目录里 /bin/mysql_safe,tar包有个 shell 文件叫 safe_mysql 也可以,这样 mysql 的守护进程就开始运行:
$ /usr/local/mysql/bin/safe_mysqld &
查看网络的3306端口情况,来判断 mysql 是否正常的运行了:
$ netstat -atln
如果没有正常运行,到 data 目录下查看日志文件查找错误。
为了方便期间,我们建立几个链接文件到 /sbin中,以免每次要到 mysql 中运行程序:
$ ln -s /usr/local/mysql/bin/mysql /sbin/mysql
$ ln -s /usr/local/mysql/bin/mysqladmin /sbin/mysqladmin
将守护进程脚本复制到初始化目录中,并加入到自动启动列表中:
$ cd mysql
$ cp support-files/mysql.server /etc/rc.d/init.d/mysqld
$修改mysqld中的 pid_file的目录!当然,目录随意最好是和已经启动的PID目录一致
$ chkconfig ――add mysqld
$ chkconfig ――level 345 mysqld on
验证上述操作的正确性,运行:
$ /etc/rc.d/init.d/mysqld restart
或者:
$ service mysqld restart
4、mysql的安全设置
运行下面指令,清除空密码帐户:
$ mysqladmin -uroot password "youpassword" #设置root帐户的密码
$ mysql -uroot -p
mysql>use mysql;
mysql>delete from user where password=""; #删除用于本机匿名连接的空密码帐号
mysql>flush privileges;
mysql>quit
最后来个测试,不过先切换到 mysql 下 msql-benmak 目录:
$ perl run-all-tests ――user=root ――password="new"
为了写程序访问 mysql 数据库,应在 /usr/include 和 /usr/lib 中建立链接到 mysql 的 include 和 lib 目录中,这样只要在程序中加入 #include 就可以引用 mysql 的头文件。
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
其中的路径及文件、文件夹名根据你的情况进行相应修改,例如我用的 tar 包中 include 目录下没有 mysql 这个文件夹,只有很多的头文件,所以我的是这样写的:
ln -s /usr/local/mysql/lib /usr/lib/mysql
ln -s /usr/local/mysql/include /usr/include/mysql
但无论如何只要它的头文件能正常的引用就可以了。
有的是可以灵活变通的,不考虑其他的因素的时候,你的mysql完全可以安装到root目录中,但是一般大家都放到 /usr/local/mysql 这个目录中。
4、perl模块的安装
很多的网页还是用 perl,为了能用 perl 语言访问 mysql,同时能运行 mysql 附带的测试程序,我安装了一些 perl 的模块。
对此,说法不一,其实你不安装业无可厚非,有的用 php 作 web 就不需要了,像我只是写应用程序访问 mysql 也是不需要安装的,但是我安装了,只是为了能测试 mysql。
我安装的模块有:
Data-Dumper-2.121
Data-ShowTable-3.3
DBD-mysql-2.9003
DBI-1.42
Msql-Mysql-modules-1.2219
Net-MySQL-0.08
mysql 手册推荐 Data-Dumper + Data-ShowTable + DBI + Msql-Mysql-modules,这样DBI就安装成功了。但是 mysql 网站上推荐的 DBI 模块中只有 DBI + Net-MySQL + DBD-mysql 三个模块,我对 perl 不熟悉,也不知道这样的 pm 文件到底用处是什么,但是有一点是肯定的,安装这样模块是没有任何的坏处的。
安装过程中 Data-ShowTable 724行代码出现错误,明显的少了两个 ">",DBD-mysql编译也出现错误,原因是路径不对,没有找到文件 mysql-config ,把你的路径加入进去编译就可以。
其他的编译都按照 readme 上去做就可以了。
5、管理工具
安装完毕后,你就可以在数据库中加入自己的东西了。
还用命令行?反正我是头大的,我觉得只要你懂就可以了,至于实际的应用就可以用一些 GUI 好点的工具,毕竟程序员的天职就是让计算机更贴近人。要不他们干嘛的?
至于mysql管理工具我推荐mysqlcc,十分好用,虽然有些地方用起来不舒服,不过有兴趣的话你自己改一下也可以,毕竟这是开源的优势嘛。
在 /usr/bin 中建立一个软连接:
ln -s /usr/local/mysqlcc/mysqlcc /usr/bin/mysqlcc
那么,Use it anywhere!
6、添加远程用户
为了能让远程的用户访问数据库,还要添加远程用户。
$ mysql -p
Enter password:*****
mysql>use mysql
mysql>grant all privileges on *.* to test@"192.168.0.%" identified by "test" with grant option;
mysql>quit;
这样就建立了一个超级用户 test,可以在本地局域网的任何地方连接,权限很大但密码很弱智,我们不想这样,但是此时,用户的权限已经开始生效了。
如果你手工修改授权表,要:
mysql>FLUSH PRIVILEGES;
或者
$ mysqladmin flush-privileges -p
此外,全局权限的改变和口令改变在下一次客户连接时生效,表和列权限在客户的下一次请求时生效,数据库权限改变在下一个 USE db_name 命令生效。
用 mysqlcc 修改 test 用户的权限,由于我不想让这个用户破坏我的数据,所以在 user 表中。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

PHP is a back-end programming language widely used in website development. It has powerful database operation functions and is often used to interact with databases such as MySQL. However, due to the complexity of Chinese character encoding, problems often arise when dealing with Chinese garbled characters in the database. This article will introduce the skills and practices of PHP in handling Chinese garbled characters in databases, including common causes of garbled characters, solutions and specific code examples. Common reasons for garbled characters are incorrect database character set settings: the correct character set needs to be selected when creating the database, such as utf8 or u

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.
